//===================================================================================================
void indexation(char const * dirPath, ...)
{
	va_list ap;
	char * tmpParam;
	int soundThread;//, textThread, pictureThread;
	PathStacks pathStack;	// Contains the path
				// of ready-to-be-indexed files
	
	// Initialise pathStack
	initStack(&pathStack.soundPathStack.pathFile);
	pathStack.soundPathStack.fileType = SOUND;
	initStack(pathStack.textPathStack.pathFile);
	pathStack.textPathStack.fileType = TEXT;
	initStack(pathStack.picturePathStack.pathFile);
	pathStack.picturePathStack.fileType = PICTURE;
	
	
	// Fill pathStack with files of the directory
	// paths given in parameter
	if(dirPath != NULL)
	{
		// First parameter isn't in ap
		updateIndexableFile(dirPath, &pathStack);
		
		va_start(ap, dirPath);
		// Browse through parameters and
		// update pathStack
		while((tmpParam = va_arg(ap, char *)) != NULL)
			updateIndexableFile(tmpParam, &pathStack);
		
		va_end(ap);
	}
Example #2
0
/*   listed in st subtree                                                    */
void generate(APTNode *root, FILE *out)
{
	int i;

	if (root == NULL)
	{
		printf("error: APT node can not be NULL!");
		exit(0);
	}


	clearAll(&SS);

	//used for processing <MINUStk> <F> expressions
	ZERO = createVElement("0");

	//used for computing expressions
	initStack(&opStack);
	initStack(&resStack);

	//list of all program variable names
	initStack(&distinctVarNames);

	//<VARtk> node not null?
	if (root->numChildren == 2)
	{
		//ADD INITIAL MARKER
		push(MARKER, &SS, 0);
		if (DEBUG) { printf("root has 2 children \n"); }

		//ADD VARIABLES TO LOCAL SCOPE
		pushExistingVars(root->children[0], &SS, out);

		//TRAVERSE TREE
		recGen(root->children[1], out);

		//REBUILD PREVIOUS CONTEXT
		popExistingVars(root->children[0], &SS, out);

		VElement* ve = pop(&SS);
	}else{
		//<VARtk> IS NULL
		if (DEBUG) { printf("root has 1 child \n"); }
		//TRAVERSE TREE
		recGen(root->children[0], out);
	}

	fprintf(out, "\tSTOP\n");

	while(!isStackEmpty(&distinctVarNames))          // allocate storage for program variables
	{
		VElement* v = pop(&distinctVarNames);
		fprintf(out, "%s\t0\n", v->data);
	}

	for (i = 0; i < varCntr; i++)      // allocate space for temporary variables
	{
		fprintf(out, "V%d\t0\n", i);
	}
}
void
constructchildtab(void *space, Suffixarray *s) {

  Uint i;
  int lastIndex = -1;
  Stack *stack;

  s->chldtab = ALLOCMEMORY(space, NULL, childtab, s->numofsuffixes);
  memset(s->chldtab, 0, s->numofsuffixes*sizeof(childtab));
  stack = ALLOCMEMORY(space, NULL, Stack, 1);
  initStack(space, stack, 100000);

  stackpush(space, stack, 1);

  for(i=1; i < s->numofsuffixes; i++) 
  {
    while(s->lcptab[i] < s->lcptab[stacktop(stack)]) {
      lastIndex = stackpop(stack);
      if(s->lcptab[i] <= s->lcptab[stacktop(stack)] && 
          s->lcptab[stacktop(stack)] != s->lcptab[lastIndex])
      {
        s->chldtab[stacktop(stack)].down = lastIndex;
        
        if (s->chldtab[stacktop(stack)].val != 0) printf("down conflict\n");
        s->chldtab[stacktop(stack)].val  = lastIndex;
      }
    }
    if (lastIndex != -1) {
      s->chldtab[i].up = lastIndex;
      
      if (s->chldtab[i-1].val != 0) printf("up conflict\n");
      s->chldtab[i-1].val = lastIndex;
      lastIndex = -1;
    }
    stackpush(space, stack, i);
  }

  /*construction of nextlIndex value*/
  destructStack(space, stack);
  initStack(space, stack, 10000);
  stackpush(space, stack,0);

  for(i=1; i < s->numofsuffixes; i++) {
    while(s->lcptab[i] < s->lcptab[stacktop(stack)]) {
      stackpop(stack);
    }
    if (s->lcptab[i] == s->lcptab[stacktop(stack)]) {
      lastIndex = stackpop(stack);
      s->chldtab[lastIndex].nextlIndex = i;  
      s->chldtab[lastIndex].val = i;
    }
    stackpush(space, stack, i);
  }

  return;
}
Example #4
0
int swap(Stack* stack, int pos1, int pos2) {
    Stack anotherStack;
    initStack(&anotherStack);

    Stack backupStack;
    initStack(&backupStack);

    Stack yetAnotherStack;
    initStack(&yetAnotherStack);

    /*
     * push all items of the primary stack, except
     * the items in positions pos1 and pos2 to the
     * backupStack; the items in pos1 and pos2 goes
     * to anotherStack.
     */
    int i,
        h = stack->top;

    for(i=stack->top ; i>=0 ; i--) {
        if(i == pos1 || i == pos2) {
            push(&anotherStack, pop(stack));
        }
        else {
            push(&backupStack, pop(stack));
        }
    }

    /*
     * pop items from another stack to yetAnotherStack.
     */
    for(i=0 ; i<2 ; i++) {
        push(&yetAnotherStack, pop(&anotherStack));
    }

    /*
     * recreate the primary stack popping items from
     * yetAnotherStack(in pos1 and pos2) and backupStack.
     */
    for(i=0 ; i<=h ; i++) {
        if(i == pos1 || i == pos2) {
            push(stack, pop(&yetAnotherStack));
        }
        else {
            push(stack, pop(&backupStack));
        }
    }
}
Example #5
0
int main(int argc, char *argv[]) {
    int i, len;
    char buf[1000];
    FILE *f;
    struct stack s;
    char *tmp;
    initStack(&s);
    if (argc == 2) {
        f =fopen(argv[1], "r"); //open with read only mod
        if ( f == NULL) {
            printf("file open fail, please check filename and privilege\n");
            return 1;
        }
        while (fscanf(f, "%s", buf) != EOF) {
            addStack(&s, buf);
        }
        while(!emptyStack(&s)) {
            printf("%s\n", tmp=deleteStack(&s));
            free(tmp); //用完再釋出記憶體空間
        }
    } else {
        printf("please specify filename as the first argument\n");
    }
    return 0;
}
Example #6
0
void traverseDFT(int g[GRAPHSIZE][GRAPHSIZE]){
    int startingNode;
    printf("\n\tDepth Fist Traversal:\n\tStarting Node: ");
    scanf("%d",&startingNode);

    VisitMark mark[GRAPHSIZE];
    List *Stack = initStack();
    int i,j;

    for (i = 0; i < GRAPHSIZE; i++){
            mark[i] = UNVISITED; // For starters, mark all nodes as UNVISITED
    }

    push(&Stack,startingNode);

    while (!isEmpty(&Stack)){
        int temp = pop(&Stack);

        if (mark[temp] == UNVISITED){
            mark[temp] = VISITED;
            printf("%d ",temp);
            for (j = 0; j < GRAPHSIZE; j++){
                if (g[j][temp] == 1){
                    push(&Stack,j);
                }
            }
        }
    }
}
Example #7
0
int main(int argc, char* argv[])
{
    /* create VirtualMachine */
    VM SVM;
    SVM.errorCode = 0;
    SVM.mode = 0;

    /* check arguments */
    if (checkArgs(argc, argv, &SVM.mode)) return 1;

    /* check configuration file */
    checkConfig(&SVM.config, &SVM.errorCode);
    if (SVM.errorCode != 0) return 1;

    /* initialization memory */
    SVM.memory.space = createMemory(SVM.config.memorySize);
    if(SVM.memory.space == NULL) return 1;
    SVM.memory.currentAddress = SVM.config.memorySize - 1;

    /* initialization stack */
    SVM.stack = initStack();

    /* start */
    if (!runVM(&SVM, argv[1])) return 1;
    return 0;
}
Example #8
0
File: calc1.c Project: shixv/test
int main(int argc,char* argv[])
{
	Stack* temp=initStack();
	Queue* postfix=initQueue();
	push(temp,'\n');
	for(int i=0;argv[1][i]!='\0';i++){
		if(isdigit(argv[1][i])){printf("%c",argv[1][i]);continue;}
		if(argv[1][i]=='('){push(temp,'(');continue;}
		if(argv[1][i]==')'){
			while(top(temp)!='('){
				printf("%c",top(temp));
				pop(temp);
			}
			pop(temp);
			continue;
		}
		if(prioritycompare(top(temp),argv[1][i])==-1)continue;
		if(prioritycompare(top(temp),argv[1][i])){
			push(temp,argv[1][i]);
			continue;
		}
		while(prioritycompare(top(temp),argv[1][i])==0){
			printf("%c",top(temp));
			pop(temp);
		}
		push(temp,argv[1][i]);
	}
	while(temp->length!=0){
		printf("%c",top(temp));
		pop(temp);
	}
	freeStack(temp);
	return 0;
}
Example #9
0
String toPrefix (String postfix) {
	
	STACK_p_t stack = initStack();
	
	int l = (int)strlen(postfix), i;
	
	for (i = 0; i < l; ++i) {
		char z = *(postfix + i);
		
		if (isOperand(z)) {
			String tempString = initString(2);
			snprintf(tempString, 2, "%c", z);
			push(stack, tempString);
		}
		
		else if (isOperator(z)) {
			String tempString = (char *)malloc(SIZE * sizeof(char));
			snprintf(tempString, SIZE, "%s%s%c", pop(stack), pop(stack), z);
			push(stack, tempString);
		}
		
	}
	
	reverse(*(stack->arr));
	return *(stack->arr);
}
Example #10
0
gboolean inRing(gint currentAtom, gint rootAtom, gint ringSize, gboolean initialize)
{
	gint i;
	if (initialize)
	{
		done = FALSE;
		bonds = 0;
		rSize = ringSize;
		initStack();
		if(nAtoms != Ncenters) buildConnectionsForRings();
		if(Ncenters<1) return FALSE;
	}
	else 
		inStack[currentAtom] = TRUE;
	if (done) return TRUE;
	else if ( ( currentAtom == rootAtom ) && ( bonds == ringSize ) ) return TRUE;
	else if ( ( currentAtom == rootAtom ) && ( bonds > 2 ) && ( ringSize < 3 ) ) return TRUE;
	if ( bonds < ringSize )
	{
		gint numberOfConnections = connected[ currentAtom ][ 0 ];
		for (i = 1; i <= numberOfConnections; i++ )
		{
			gint newAtom = connected[currentAtom][i];
			if ( ! ( inStack[newAtom] ) )
			{
				bonds++;
				done = inRing( newAtom, rootAtom, ringSize, FALSE );
			}
			if (done) return TRUE;
		}
	}
	inStack[currentAtom] = FALSE;
	bonds--;
	return FALSE;
}
Example #11
0
int main(int argc, char *argv[])
{
	int i;
	long data;
	struct Stack *stack;

	srand(time(NULL));
	stack = initStack(100);
	if (NULL == stack)
		return -1;

	for (i = 0; i < LEN; i++) {
		push(stack, rand() % 100);
	}
	putchar('\n');

	for (i = 0; i < LEN; i++) {
		pop(stack, &data);
		printf("%ld	", data);
	}
	putchar('\n');

	destryStack(stack);

	return 0;
}
Example #12
0
//------------------------------------------------------------------------------
// An adaptation of the loop in main() in the original Babuino code.
// This is intended to be called from within the Arduino loop() function.
//------------------------------------------------------------------------------
void 
Babuino::loop()
{
	debounce();
	
	switch (_states.getMachineState())
		{
		case READY:
			if (serialAvailable() > 0)
			{
				_states.setMachineState(COMM);
			}
			else if (_states.getRunRequest() == RUNNING)
			{
				_states.setMachineState(RUN);
			}
			break;

		case COMM:
			doComm();
			_states.setMachineState(READY);
			break;

		case RUN:
			_regs.pc.set(_storage.getStartAddress());
			initStack(_stack);
			_states.setMachineState(RUN);
			code_exec();
			_motors.off();
			_states.setMachineState(READY);
			break;
		}
}
Example #13
0
static bool
getRefValues(
    uint		module,
    uchar		noun,
    uchar		verb,
    uchar		cond,
    uchar		seq,
    uchar*	refNoun,
    uchar*	refVerb,
    uchar*	refCond)
{
    //	set reference values for this message, returning FALSE if message not
    //	found.

    IndexEntry far*	indexEntry;
    MsgStack				stack;

    //	use a local stack, since no need to save info across calls
    initStack(&stack, module, noun, verb, cond, seq);

    if (!find(&stack, &indexEntry, FALSE))
        return FALSE;

    *refNoun = indexEntry->refNoun;
    *refVerb = indexEntry->refVerb;
    *refCond = indexEntry->refCond;

    return TRUE;
}
Example #14
0
static void
getSize(
    uint		module,
    uchar		noun,
    uchar		verb,
    uchar		cond,
    uchar		seq)
{
    //	return size of buffer needed to hold the message, including trailing
    //	NULL, or 0 if message not found
    //	stage directions are included in the size

    MsgStack		stack;
    char far*	cp;

    //	use a local stack, since no need to save info across calls
    initStack(&stack, module, noun, verb, cond, seq);

    cp = find(&stack, NULL, TRUE);

    if (!cp)
        acc = 0;

    else {
        int len;
        for (len = 0; *cp; cp++, len++)
            ;
        //	add one for trailing null
        acc = len + 1;
    }
}
int readConvert(char post[]) {
	char getToken(void), token, c;
	int precedence(char);
	StackData temp;
	int h = 0;
	Stack S = initStack();
	printf("Type an infix expression and press Enter\n");
	token = getToken();
	while (token != '\n') {
		if (isdigit(token)) post[h++] = token;
		else if (token == '(') {
			temp.ch = token;
			push(S, temp);
		}
		else if (token == ')')
			while ((c = pop(S).ch) != '(') post[h++] = c;
		else {
			while (!empty(S) &&
						 precedence(peek(S).ch) >= precedence(token))
				post[h++] = pop(S).ch;
			temp.ch = token;
			push(S, temp);
		}
		token = getToken();
	} //end while
	while (!empty(S)) post[h++] = pop(S).ch;
	return h; //the size of the expression
} //end readConvert
Example #16
0
int main(int argc, const char * argv[]) {
    
    
    ElemType c;
    SqStack s;
    int len,i,sum = 0;
    
    printf("Please input a Binary digit\n");
    
    initStack(&s);
    scanf("%c",&c);
    while (c!= '#')
    {
        Push(&s, c);
        scanf("%c",&c);
    }
    getchar();
    
    len = StackLen(s);
    
    for (i = 0 ; i <len ; i++)
    {
        Pop(&s, &c);
        sum = sum + (c-48) * pow(2, i);
    }
    printf("Decimal is %d\n",sum);
    return 0;
}
char* simplifyPath(char* path) {
    int len = strlen(path);
    if (!path || len < 2)   return path;
    Stack stack;
    if (*(path + len - 1) == '/') {
        len--;
        *(path + len) = '\0';
    }
    char *str = (char *)malloc(sizeof(char)* (len + 1));
    initStack(&stack, len);
    int status;
    while (status = getElem(&path, str)) {
        if (status == 1) {
            pushStack(&stack, str);
        } else if(status == 2){
            popStack(&stack);
        }
    }
    if (stack.top == 0) {
        stack.elem[0] = '/';
        stack.top = 1;
        stack.pos[stack.top] = 1;
    }
    stack.elem[stack.pos[stack.top]] = '\0';
    return stack.elem;
}
Example #18
0
void depthFirstSearchNonRec(Graph *graph, int visited[], int vertex) {
//mark it as visited
    int i, currVertex;
    Stack *stack;
    visited[vertex] = 1;

    stack = initStack(graph->V);
    push(stack, vertex);

    //push vertex on stack
    while(!isEmpty(stack)) { //stack not empty
        //pop node from top of stack
        currVertex = pop(stack);

        visited[currVertex] = 1;
        printf(" %d,", currVertex);

        //visit all its neighbours
        for(i = graph->V - 1; i >=0 ; i--) {
            //if neighbour is not visited then
            if((graph->edgeMat[currVertex][i] == 1) && (visited[i] == 0)) {
                 //push it on top of the stack
                 push(stack, i);
            }
            //do for all vertices
        }
    }
    releaseStack(stack);
}
Example #19
0
task main(){
	calibrateLight();
	calibrateCompass();
	ExploreStack stack;
	Graph graph;

	initStack(stack);
	initGraph(graph);
	Stub stub;
	Edge lastEdge;

	int currentNode = -1;
	int canNode = -1;
	//go to node
	currentNode = exploreNewNode(graph, stack, currentNode, lastEdge);
	if(detectCan()) {
		canNode = currentNode;
		announceCan(currentNode);
	}
	//while not empty
	while(!empty(stack)){
		pop(stack, stub);
		motor[left] = 0;
		motor[right] = 0;
		goToNode(graph, currentNode, stub.node);
		currentNode = stub.node;
		turnToAngle(stub.angle, 15);
		turnToLine();
		nxtDisplayCenteredTextLine(4, "Exploring...");
		int stackSize = stack.top;
		FollowSegmentTilEnd(lastEdge);
		currentNode = exploreNewNode(graph, stack, currentNode, lastEdge);
		if(stackSize == stack.top && detectCan()) {
			canNode = currentNode;
			announceCan(currentNode);
		}
	}
	motor[left] = 0;
	motor[right] = 0;
	eraseDisplay();
	nxtDisplayCenteredTextLine(3, "%i nodes found", graph.nNodes);
	wait10Msec(500);


	if(canNode >= 0) {
		goToNode(graph, currentNode, canNode);
		motor[left] = 0;
		motor[right] = 0;
		eraseDisplay();
		nxtDisplayCenteredTextLine(3, "Can was here");
		wait10Msec(500);
	} else {
		motor[left] = 0;
		motor[right] = 0;
		eraseDisplay();
		PlaySound(soundLowBuzz);
		nxtDisplayCenteredTextLine(3, "There was no can");
		wait10Msec(500);
	}
}
int main(int argc, char *argv[])
{
  psqStack my_stack = (psqStack)malloc(sizeof(sqStack));
  initStack(&my_stack);

  char bin;          // 用于接收用户的输入的01,作为字符串处理
  int  decimal = 0;  // 用户接收最后生成的10进制数字
  while ((bin = getchar())!='\n') {      // 当有回车的时候跳出循环.
    if (bin == '1' || bin == '0') {
      Push(my_stack, (int)atof(&bin));     // 注意这里atof返回的是double, 所以要强制类型转换
    }
    else
      {
        printf("You must enter 1 or 0\n");
        return ERROR;
      }
  }

  Show(my_stack);

  int popped_e;
  int len = StackLength( my_stack );
  for (int i = 0; i < len; i++) {
    Pop(my_stack, &popped_e);
    decimal += popped_e * (int)pow(2, i);
  }

  printf(" decimal = %d\n", decimal);

  return 0;
}
Example #21
0
static void findOcamlTags (void)
{
	vString *name = vStringNew ();
	lexingState st;
	ocaToken tok;

	initStack ();
	computeModuleName ();
	tempIdent = vStringNew ();
	lastModule = vStringNew ();
	lastClass = vStringNew ();
	voidName = vStringNew ();
	vStringCopyS (voidName, "_");

	st.name = vStringNew ();
	st.cp = fileReadLine ();
	toDoNext = &globalScope;
	tok = lex (&st);
	while (tok != Tok_EOF)
	{
		(*toDoNext) (st.name, tok);
		tok = lex (&st);
	}

	vStringDelete (st.name);
	vStringDelete (name);
	vStringDelete (voidName);
	vStringDelete (tempIdent);
	vStringDelete (lastModule);
	vStringDelete (lastClass);
	clearStack ();
}
Example #22
0
int* inorderTraversal(struct TreeNode* root, int* returnSize) {
    Stack S;
    struct TreeNode *node;
    int *arr;
    int i = 0;
    initStack(&S);
    arr = (int*)malloc(100 * sizeof(int));
    node = root;
    while(node || !isEmpty(S))
    {
        while(node)
        {
            push(&S, node);
            node = node->left;
        }
        if(!isEmpty(S))
        {
            pop(&S, &node);
            *(arr + i) = node->val;
            i++;
            node = node->right;
        }
        
    }
    destroyStack(&S);
    *returnSize = i;
    return arr;
}
Example #23
0
int main(){
	char prefixBuffer[STR_SIZE*2];
	int prefixIndex = 0;
	double result = 0.0;

	STACK charStack;
	STACK intStack;

	initStack(&charStack, "char");
	initStack(&intStack, "double");

	makePrefix(prefixBuffer, &charStack, &prefixIndex);
	result = calcPrefix(prefixBuffer, &intStack, &prefixIndex);

	printf(" %.2lf \n", result);

	return 0;
}
int main() {
	Stack initStack();
	int empty(Stack);
	void push(Stack, int);
	int pop(Stack);
	int n;
	Stack S = initStack();
   printf("Enter some integers, ending with 0\n");
	scanf("%d", &n);
	while (n != 0) {
		push(S, n);
		scanf("%d", &n);
	}
	printf("Numbers in reverse order\n");
	while (!empty(S))
		printf("%d ", pop(S));
	printf("\n");
} //end main
Example #25
0
 Uint *quickSort(void *space, void* toSort, Uint size, 
 					Uint (*cmp)(Uint, Uint, void *, void*),
					void *info) {
 	Stackelement left, left2, right, right2;
	Uint i, resc, *sorted, x;
	Stack stack;
	
	sorted = ALLOCMEMORY(space, NULL, Uint, size);
	for (i=0; i < size; i++) sorted[i]=i;
	
	initStack(space, &stack, 10000);	
	stackpush(space, &stack, 0);
	stackpush(space, &stack, size-1);	
   
	while (!stackisempty(&stack)) {
		right=stackpop(&stack);
		left=stackpop(&stack);	
		
		while (left < right) {
			x=sorted[(left+right)/2];
			left2  = left;
			right2 = right;
	
			do {
			    while(cmp(sorted[left2],  x, toSort, info)==2){	
				  left2++;
				}
				while(cmp(sorted[right2], x, toSort, info)==1){ 
				  right2--;
				}
			
				if(left2 <= right2) {
						resc = sorted[right2];
						sorted[right2]=sorted[left2];
						sorted[left2]=resc;						
						left2++;
						right2--;
			 	} 	
			} while (right2 >= left2);
			

			if ((left2-left) > (right-left2))  {
			/*if ((right2-left) > (right-left2)) {*/
				stackpush(space, &stack, left);
				stackpush(space, &stack, right2);		
				left  = left2;
			} else {
				stackpush(space, &stack, left2);
				stackpush(space, &stack, right);
				right = right2;
			}
		}
	}
	destructStack(space, &stack);	
 	return sorted;
 }
int main()
{
	Stack s;
	int result;
	char array[255];

	initStack(&s, 1000);
	result = checkFile(&s);
	printf("%d", result);
}
Example #27
0
void initTreeMolecule(TreeMolecule* treeMolecule, GeomDef*  geom, gint NAtoms, gint ringSize)
{
	treeMolecule->done = FALSE;
	treeMolecule->bonds = 0;
	treeMolecule->ringSize = ringSize;
	treeMolecule->nAtoms = NAtoms;
	if(NAtoms<1) return;
	initStack(treeMolecule);
	initConnections(treeMolecule, geom);
}
Example #28
0
int main(int argc, char** argv) {
    Stack *mStack;
    initStack(mStack);

    printf("length = %d\n",1);
    push(mStack,100);
    printf("length = %d\n",mStack->top);
    printf("data = %d\n",pop(mStack));
    return (EXIT_SUCCESS);
}
Example #29
0
File: stack.c Project: Jessycah/C
int main(){
	STACK s;
	initStack(&s);
	printS(&s);
	push(&s, 1); push(&s, 2); push(&s, 2); push(&s, 2); push(&s, 2); push(&s, 2); 
	printS(&s);


	return 1;
}
Example #30
0
void
closest_pairs2graph(double *place, int n, int num_pairs, vtx_data ** graph)
{
    /* build a graph with with edges between the 'num_pairs' closest pairs in the 1-D space: 'place' */
    PairStack pairs_stack;
    initStack(&pairs_stack, num_pairs);
    find_closest_pairs(place, n, num_pairs, &pairs_stack);
    construct_graph(n, &pairs_stack, graph);
    freeStack(&pairs_stack);
}