Esempio n. 1
0
void printStack(stack* s){

  if(emptyStack(s) == 1){

    printf("\nThe stack is empty.\n");
    return;
  }
  stack* tempS = createStack();
  dnode* tempN = frontStack(s);
  data* d = createData(tempN->d->i1,tempN->d->i2,tempN->d->f1);
  while(emptyStack(s) != 1){

    tempN = frontStack(s);
    printData(tempN->d);
    d = createData(tempN->d->i1,tempN->d->i2,tempN->d->f1);
    pushStack(tempS,d);
    popStack(s);
  }
  while(emptyStack(tempS) != 1){

    tempN = frontStack(tempS);
    d = createData(tempN->d->i1,tempN->d->i2,tempN->d->f1);
    pushStack(s,d);
    popStack(tempS);
  }
  return;
}
Esempio n. 2
0
//===================================================================
// Function to undo a delete of a company.  Does not allow to undo
// delete of a company that is already in the BST
//===================================================================
void undoDelete(DATA_HEAD *data)
{
    COMPANY* companyNode;
    int isDuplicate;

    //If there is something in the stack
    if(!emptyStack(data->pStack))
    {
        companyNode = (COMPANY*)popStack(data->pStack);

        //Check to see if there is duplicate
        isDuplicate = searchHash(data, companyNode->companyName, companyNode);

        //If there is, print and error, else, insert into the hashed array
        if(isDuplicate == 1)
        {
            printf("ERROR: DUPLICATE DATA\n");
            printf("%s has already been entered into the system\n", companyNode->companyName);
            free(companyNode);
        }
        else
        {
            printf("%s reinserted into the system\n", companyNode->companyName);
            insertManager(data, companyNode);
            updateCollision(data);
            (data->count)++;
            printf("\nNumber Of Data Records: %d\n", data->count);
        }
    }
    else
        printf("Nothing to undo.\n"); //nothing in the stack

    printf("\n");
}
/*--------------------------------
convert infix to postfix
--------------------------------*/
void infixToPostfix(char infix[max], char postfix[max]){
	emptyStack();
	int i=0,j=0;
	while(infix[i]!='\0'){
		if(isOperator(infix[i])!=1){ // if is operand
			postfix[j++]=infix[i];
		}else if(infix[i]== '(')
			push(infix[i]);
		else if(infix[i]==')'){
			while(stack[top]!='(')
				postfix[j++]=pop();
			top--;
		}else{
			while(top!=-1 && prcd(infix[i])<=prcd(stack[top]))
				postfix[j++]=pop();
			push(infix[i]);
		}
		i++;
	}
	while(top!=-1)
		if(stack[top]!=')' || stack[top]!='(')
			postfix[j++]=pop();
		else top--;
	postfix[j]='\0';
}
Esempio n. 4
0
File: stack.c Progetto: TerraPi/VM
stackElementT pop(stackT *stackP){
	if(emptyStack(stackP)){
		fprintf(stderr, "Can't pop element from stack: stack is empty. \n");
		exit(1);
	}
	return stackP->contents[stackP->top--];
}
Esempio n. 5
0
int main(int argc, char **argv)
{
	int N = (argc < 2) ? 20 : atoi(argv[1]);
	if (N < 20) N = 20;
	Stack s = newStack();
	int i;
	char x[50];
	for (i = 0; i < N; i++) {
		if (random()%10 > 5) {
			if (!emptyStack(s)) {
				char *str = popFrom(s);
				printf("Remove %s\n",str);
				free(str);
			}
		}
		else {
			randomString(x);
			pushOnto(s,x);
			printf("Insert %s\n",x);
		}
		showStack(s);
	}
	disposeStack(s);
	return 0;
}
int main(){
	bracHold *head=NULL;
	bracHold *tail=NULL;
	char scanChar,popChar;
	int flag=0;
	while(scanf("%c",&scanChar)!=EOF){
		if((scanChar=='(') || (scanChar=='{') || (scanChar=='[')){
			push(&head,&tail,scanChar);
		//	print(&head);
		}
		else if((scanChar==')') || (scanChar=='}') || (scanChar==']')){
			if(!emptyStack(&head)){
				popChar=pop(&head,&tail);
				//printf("poped->%c\n",popChar);
				if(scanChar==')' && popChar=='(')
					continue;
				else if(scanChar=='}' && popChar=='{')
					continue;
				else if(scanChar==']' && popChar=='[')
					continue;
				else{
					flag=1;
					printf("Not Valid\n");
					break;
				}
			}
			else{
				printf("Not Valid\n");
			}
		}
	}
	if(flag==0)
		printf("Valid\n");
	return 0;
}
Esempio n. 7
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;
}
Esempio n. 8
0
void Waltz::setSensor(const AbstractSensor& _sensor) {
	sensor = &_sensor;
	emptyStack();
	currentLocation = zero;
	memory.clear();
	timeLeft = INT_MAX;
	batteryRemianing = config.BatteryCapacity;
}
Esempio n. 9
0
///********************************
///Function: top
///Task: as long as the stack is not empty, returns the double on the top of the stack
///Returns: top element from the stack
///********************************
double calcStack::top() const
{
    if (isEmpty())
    {
        throw emptyStack();
    }
    return nums[topIndex];
}
Esempio n. 10
0
///********************************
///Function: pop
///Task: as long as the stack is not empty, removes the top element from the stack by decrementing topIndex
///Returns: nothing
///********************************
void calcStack::pop()
{
    if (isEmpty())
    {
        throw emptyStack();
    }
    topIndex--;
}
Esempio n. 11
0
int pop(struct Stack *stack, long *data)
{
	if (emptyStack(stack)) {
		fprintf(stderr, "%s", "\nempty stack!\n");
		return -EEMPTYSTACK;
	}

	*data = stack->stack[--stack->sp];

	return 0;
}
Esempio n. 12
0
void constructChildValues(ESA *esa)
{

   int n = esa->n+1;
   
   stack *s = newStack();
   
   push(s, 0);
   
   // TODO: Make sure that this correctly reaches the end.
   for (int i=1; i<n; i++)
   {   
      while (esa->LCP[i] < esa->LCP[ peek(s) ])
         pop(s);
         
      if (esa->LCP[i] == esa->LCP[ peek(s) ])
         esa->accross[pop(s)] = i;
   
      push(s, i);      
   }
   
   /**   Construct Up/Down values.   ***************/
   
   // Reset the stack.   
   emptyStack(s);
   
   int lastIndex = -1;
   push(s, 0);
   for (int i=1; i<n; i++)
   {
      while (esa->LCP[i] < esa->LCP[ peek(s) ] )
      {
         lastIndex = pop(s);
         int top   = peek(s);
         
         if (    esa->LCP[i]   <= esa->LCP[top] 
              && esa->LCP[top] != esa->LCP[lastIndex] )
              
            esa->down[top] = lastIndex;
         
         if (lastIndex != -1)
         {
            esa->up[i] = lastIndex;
            lastIndex  = -1;
         }
      }     
      push(s, i);
   }  
   
   freeStack(s);
}
Esempio n. 13
0
Operand popOperand(OperandStack **topAddress) {
	OperandStack *p1;
	Operand operand;
	if (!emptyStack(*topAddress)) {
		operand = (*topAddress)->operand;
		p1 = *topAddress;
		*topAddress = (*topAddress)->nextOperand;
		free(p1);
	} else {
		printf("A pilha esta vazia\n");
		exit(1);
	}
	return operand;
}
Esempio n. 14
0
//===================================================================
// Writes to output file and calls function to clear out the stack
//===================================================================
void saveToFile(DATA_HEAD *data) {
    COMPANY *temp;
    FILE *outputFile;
    char filename[MAX_CHARS];
    int i, len;
    char ch;

    do {
        printf("Please enter a filename for output file [enter for default]:");
        fgets(filename, MAX_CHARS, stdin);

        if (filename[0] == '\n')
            strcpy(filename, "out.txt");
        else {
            //flush new line
            len = strlen(filename);
            if (filename[len - 1] == '\n' || filename[len - 1] == '\r')
                filename[len - 1] = '\0'; // change '\n' to '\0'
            else
                while ((ch = getchar()) != '\n' && ch != '\r');
        }

        outputFile = fopen(filename, "w");
    } while (!outputFile);

    //Writes to output file in hashed sequence
    printf("Writing to %s...\n", filename);

    for (i = 0; i < data->arraySize; i++) {
        if (data->pHash[i].status == 1) //status is filled, data exists at index
            fprintf(outputFile, "%s,%d,%d,%d\n", data->pHash[i].hashData->companyName, data->pHash[i].hashData->revenuePerBillion, data->pHash[i].hashData->profitPerMillion, data->pHash[i].hashData->numberOfEmployees);
    }
    //need to free the company name as well as the company
    //modifying stack ADT does not work since this is specific to this program
    while (!emptyStack(data->pStack)) {
        temp = (COMPANY *)popStack(data->pStack); //pop everything from the stack
        free(temp->companyName); //free company name and then company
        free(temp);
    }

    data->pStack->count = 0; //reset stack
    data->pStack->top = NULL;

    fclose(outputFile);
    printf("\n");
}
Esempio n. 15
0
/**
 * Push one element in the stack
 * @param STACK **head pointer to the stack
 * @param char *value The value that you want to enqueue in the stack
 */
void pushElement(STACK **head, char *value) {
    STACK *buffer;
    buffer = malloc(sizeof (STACK));

    if (buffer != NULL) {
        buffer->value = (char*) malloc(sizeof (char) * strlen(value));
        memcpy(buffer->value,value, strlen(value)+1);
        if( emptyStack(head) ) {
            buffer->link = NULL;
        } else {
            buffer->link = *head;
        }
        *head = buffer;
    } else {
        fputs("Not enough memory.", stdout);
        abort();
    }
}
Esempio n. 16
0
File: Test.c Progetto: TerraPi/VM
int main(){

	char string[] = "istore 12 32";
	char *ptr;

	ptr = strtok(string, delimiter);

	while(ptr != NULL) {
		printf("Abschnitt gefunden: %s\n", ptr);
		ptr = strtok(NULL, delimiter);
	}

	FILE *fp;
	int i, temp;
	fp = fopen("test.ovm", "r");
	if(fp == NULL) {
		printf("Datei konnte nicht geöffnet werden.\n");
	}else {
		while((temp = fgetc(fp))!=EOF) {
			printf("%c ", temp);
		}
		fclose(fp);
	}
	printf("\n");

	stackT s1;
	memoryT m1;
	initStack(&s1, 10);
	initMemory(&m1, 10);
	push(&s1, 'Z');
	set(&m1, 'L', 2);
	while(!emptyStack(&s1)){
		printf("%c", pop(&s1));
	}
	printf("%c", get(&m1, 2));
	return 0;
}
Esempio n. 17
0
static int
cs_operate(int (*func)(struct frame_state const *, void *), void *usrarg,
           size_t starting_frame, size_t num_frames)
{
  dbghelp_functions dbg;
  if (!load_dbghelp_library_if_needed (&dbg))
    {
      ACE_OS::strcpy (static_cast<char *> (usrarg),
                      "<error loading dbghelp.dll>");
      if (dbg.hMod) FreeLibrary (dbg.hMod);
      return 1;
    }

  frame_state fs;
  ZeroMemory (&fs.sf, sizeof (fs.sf));
  fs.pDbg = &dbg;
  emptyStack ();   //Not sure what this should do, Chad?

  CONTEXT c;
  ZeroMemory (&c, sizeof (CONTEXT));
  c.ContextFlags = CONTEXT_FULL;

#  if defined (_M_IX86)
  DWORD machine = IMAGE_FILE_MACHINE_I386;
  __asm {
    call x
    x: pop eax
    mov c.Eip, eax
    mov c.Ebp, ebp
    mov c.Esp, esp
  }
  fs.sf.AddrPC.Offset = c.Eip;
  fs.sf.AddrStack.Offset = c.Esp;
  fs.sf.AddrFrame.Offset = c.Ebp;
  fs.sf.AddrPC.Mode = AddrModeFlat;
  fs.sf.AddrStack.Mode = AddrModeFlat;
  fs.sf.AddrFrame.Mode = AddrModeFlat;
#  elif defined (_M_X64)
  DWORD machine = IMAGE_FILE_MACHINE_AMD64;
  RtlCaptureContext (&c);
  fs.sf.AddrPC.Offset = c.Rip;
  fs.sf.AddrFrame.Offset = c.Rsp; //should be Rbp or Rdi instead?
  fs.sf.AddrStack.Offset = c.Rsp;
  fs.sf.AddrPC.Mode = AddrModeFlat;
  fs.sf.AddrFrame.Mode = AddrModeFlat;
  fs.sf.AddrStack.Mode = AddrModeFlat;
#  elif defined (_M_IA64)
  DWORD machine = IMAGE_FILE_MACHINE_IA64;
  RtlCaptureContext (&c);
  fs.sf.AddrPC.Offset = c.StIIP;
  fs.sf.AddrFrame.Offset = c.RsBSP;
  fs.sf.AddrBStore.Offset = c.RsBSP;
  fs.sf.AddrStack.Offset = c.IntSp;
  fs.sf.AddrPC.Mode = AddrModeFlat;
  fs.sf.AddrFrame.Mode = AddrModeFlat;
  fs.sf.AddrBStore.Mode = AddrModeFlat;
  fs.sf.AddrStack.Mode = AddrModeFlat;
#  endif

  fs.pSym = (PSYMBOL_INFO) GlobalAlloc (GMEM_FIXED,
                                        sizeof (SYMBOL_INFO) +
                                        sizeof (ACE_TCHAR) * (SYMSIZE - 1));
  fs.pSym->SizeOfStruct = sizeof (SYMBOL_INFO);
  fs.pSym->MaxNameLen = SYMSIZE * sizeof (ACE_TCHAR);
  dbg.SymSetOptions (SYMOPT_DEFERRED_LOADS | SYMOPT_LOAD_LINES
                     | SYMOPT_FAIL_CRITICAL_ERRORS | dbg.SymGetOptions ());
  dbg.SymInitialize (GetCurrentProcess (), 0, true);
  //What does the "true" parameter mean when tracing the current process?

  for (size_t current_frame = 0; current_frame < num_frames + starting_frame;
       ++current_frame)
    {
      BOOL ok = dbg.StackWalk64 (machine,
                                 GetCurrentProcess (),
                                 GetCurrentThread (),
                                 &fs.sf, &c, 0,
                                 dbg.SymFunctionTableAccess64,
                                 dbg.SymGetModuleBase64, 0);
      if (!ok || fs.sf.AddrFrame.Offset == 0)
        break;

      if (current_frame < starting_frame)
        continue;

      func (&fs, usrarg);
    }

  dbg.SymCleanup (GetCurrentProcess ());
  GlobalFree (fs.pSym);
  FreeLibrary (dbg.hMod);

  return 0;
}
Esempio n. 18
0
//search linear structure starting with the root of a tree
static int startEdgeFromNode ( kmer_t * node1, FILE * fp )
{
	int node_c, palindrome;
	unsigned char flag;
	KMER_PT * ite_pt, *temp_pt;
	Kmer word1, bal_word1;
	char ch1;

	if ( node1->linear || node1->deleted )
		{ return 0; }

	// ignore floating loop
	word1 = node1->seq;
	bal_word1 = reverseComplement ( word1, overlaplen );

	// linear structure
	for ( ch1 = 0; ch1 < 4; ch1++ )     // for every node on outgoing list
	{
		flag = get_kmer_right_cov ( *node1, ch1 );

		if ( !flag )
			{ continue; }

		emptyStack ( nodeStack );
		temp_pt = ( KMER_PT * ) stackPush ( nodeStack );
		temp_pt->node = node1;
		temp_pt->isSmaller = 1;
		temp_pt->kmer = word1;
		stringBeads ( temp_pt, ch1, &node_c );

		//printf("%d nodes\n",node_c);
		if ( node_c < 2 )
			{ printf ( "%d nodes in this line!!!!!!!!!!!\n", node_c ); }
		else
		{
			//make a reverse complement node list
			stackBackup ( nodeStack );
			emptyStack ( bal_nodeStack );

			while ( ( ite_pt = ( KMER_PT * ) stackPop ( nodeStack ) ) != NULL )
			{
				temp_pt = ( KMER_PT * ) stackPush ( bal_nodeStack );
				temp_pt->kmer = reverseComplement ( ite_pt->kmer, overlaplen );
			}

			stackRecover ( nodeStack );
			palindrome = check_iden_kmerList ( nodeStack, bal_nodeStack );
			stackRecover ( nodeStack );

			if ( palindrome )
			{
				merge_linearV2 ( 0, nodeStack, node_c, fp );
			}
			else
				{ merge_linearV2 ( 1, nodeStack, node_c, fp ); }
		}
	} //every possible outgoing edges

	for ( ch1 = 0; ch1 < 4; ch1++ )     // for every node on incoming list
	{
		flag = get_kmer_left_cov ( *node1, ch1 );

		if ( !flag )
			{ continue; }

		emptyStack ( nodeStack );
		temp_pt = ( KMER_PT * ) stackPush ( nodeStack );
		temp_pt->node = node1;
		temp_pt->isSmaller = 0;
		temp_pt->kmer = bal_word1;
		stringBeads ( temp_pt, int_comp ( ch1 ), &node_c );

		if ( node_c < 2 )
			{ printf ( "%d nodes in this line!!!!!!!!!!!\n", node_c ); }
		else
		{
			//make a reverse complement node list
			stackBackup ( nodeStack );
			emptyStack ( bal_nodeStack );

			while ( ( ite_pt = ( KMER_PT * ) stackPop ( nodeStack ) ) != NULL )
			{
				temp_pt = ( KMER_PT * ) stackPush ( bal_nodeStack );
				temp_pt->kmer = reverseComplement ( ite_pt->kmer, overlaplen );
			}

			stackRecover ( nodeStack );
			palindrome = check_iden_kmerList ( nodeStack, bal_nodeStack );
			stackRecover ( nodeStack );

			if ( palindrome )
			{
				merge_linearV2 ( 0, nodeStack, node_c, fp );
				//printf("edge is palindrome with length %d\n",temp_edge.length);
			}
			else
				{ merge_linearV2 ( 1, nodeStack, node_c, fp ); }
		}
	} //every possible incoming edges

	return 0;
}
Esempio n. 19
0
int main(int argc,char* argv[]){

  printf("\nPROGRAM BEGUN\n");

//generating a readable .txt file
  srand(time(NULL));
  FILE* out = fopen(argv[2],"w");
  int i;
  int v1;
  int v2;
  float v3;
  for(i = 0;i < atoi(argv[1]);i++){

    v1 = rand() % 100;
    v2 = rand() % 200;
    v3 = (rand() % 10000)/100.00;
    fprintf(out,"%d %d %f\n",v1,v2,v3);
  }
  fclose(out);

//opening the generated .txt file w/ read privileges
//then reading the data structures into a stack
  FILE* read = fopen(argv[2],"r");
  stack* s = createStack();
  data* d = malloc(sizeof(data));
  while(1){

    d = readData(read);
    if(d == NULL){

      break;
    }
    pushStack(s,d);
  }

//printing the stack
  printf("\nPRINTING STACK\n\n");
  printStack(s);

//creating a queue and pushing the data from the stack to it
  dnode* tempN = frontStack(s);
  queue* q = createQueue();

//remember that to do this we must:
//1. begin a while loop that runs while [emptyStack(s) != 0]
//2. set a temp dnode equal to the head of the stack
//3. create a NEW data structure from the data within this temp dnode
//4. use the pushQueue function with this newly created data struct
//5. pop the front element off of the stack, effectively deleting it
  while(emptyStack(s) != 1){

    tempN = frontStack(s);
    d = createData(tempN->d->i1,tempN->d->i2,tempN->d->f1);
    pushQueue(q,d);
    popStack(s);
  }

//printing the queue
  printf("\nPRINTING QUEUE\n\n");
  printQueue(q);
  if(emptyStack(s) == 1){

    printf("\nSTACK EMPTY\n\n");
  }
  return 0;
}
Esempio n. 20
0
int main ()
{
  int i;
  double result;

  if (getStackSize() ==0)
    printf ("Passed 1\n");
  else
    printf ("Failed 1\n");

  /* Make sure a pop of an empty stack returns NAN.*/
  result = pop();
  if (isnan(result))
    printf ("Passed 2\n");
  else
    printf ("Failed 2\n");

  
  /* Check if an empty stack returns a non-zero (true) value. */
  emptyStack();

  if (isStackEmpty())
    printf ("Passed 3\n");
  else
    printf ("Failed 3\n");

  /************************************************
  /* Push 15 values on the stack -- 
     Check result, isStackEmpty, and getStackSize */
  for (i=0; i<15; i++)
    result = push (i);

  if (result == 0)
    printf ("Passed 4\n");
  else
    printf ("Failed 4\n");
  
  if (getStackSize() == 15)
    printf ("Passed 5\n");
  else
    printf ("Failed 5\n");

  if (!isStackEmpty())
    printf ("Passed 6\n");
  else
    printf ("Failed 6\n");

  /************************************************
  /* Check two pops */
  /* Then make sure stack size is now 13.
   */
  if (pop() == 14)
    printf ("Passed 6\n");
  else
    printf ("Failed 6\n");

  if (pop() == 13)
    printf ("Passed 7\n");
  else
    printf ("Failed 7\n");

  if (getStackSize() == 13)
    printf ("Passed 8\n");
  else
    printf ("Failed 8\n");

  /************************************************
  * Push 100 values on the stack -- 
  * All should have a result of 0.
  * Then push a 101th value and make sure the result is -1.  
  */
  emptyStack();
  
  for (i=0; i<100; i++) {
    result = push (i);
    if (result != 0) {
      printf("Push 100 failed on %d\n", i);
      break;
    }
  }
    
  result = push(101);
  if (result == -1) 
    printf ("Passed 9\n");
  else
    printf ("Failed 9\n");
}  
Esempio n. 21
0
int main()
{
    FILE *fp;
    Pile pile;
    tInfo info;
    char op;
    printf("\t\t\tEjercicio 4 tp3 Pila estatica\n");

    if(!openFile(&fp,"r+b",FILENAME,!CON_SIN_MSJ))
    {
        createFile();
        if(!openFile(&fp,"r+b",FILENAME,CON_SIN_MSJ))
            return 0;
    }
    createStack(&pile);
    fread(&info,1,sizeof(tInfo),fp);
    while(!feof(fp) && !isStackFull(&pile))
    {
        putInStack(&pile,&info);
        fread(&info,1,sizeof(tInfo),fp);
    }
    fclose(fp);
    op = menuOption(MSJ,OPTION);
    while(op != 'D')
    {
        switch(op)
        {
        case 'A':
            {
                newInfo(&info);
                if(putInStack(&pile, &info) == PILA_LLENA)
                    puts("pila llena no se pudo cargar la nueva informacion");
                break;
            }
        case 'B':
            {
                puts("Viendo tope de la pila: ");
                if(showTop(&pile,&info) != PILA_VACIA)
                    showInfo(&info);
                else
                    puts("Pila vacia, no se puede ver tope");
                break;
            }
        case 'C':
            {
                puts("Sacando de pila...");
                if(takeOfStack(&pile,&info) != PILA_VACIA)
                    showInfo(&info);
                else
                    puts("No se puede sacar de pila, pila vacia");

                break;
            }
        }
        op = menuOption(MSJ,OPTION);
    }
    if(!openFile(&fp,"r+b",FILENAME,CON_SIN_MSJ))
    {
        puts("Vaciando pila...");
        emptyStack(&pile);
        return 0;
    }
    while(!isStackEmpty(&pile))
    {
        takeOfStack(&pile,&info);
        putInTheEndFile(&fp,&info);
    }
    emptyStack(&pile);
    fclose(fp);
    return 0;
}
Esempio n. 22
0
void
scan_fill_do_action(int x, int y, texture_info * tex, VALUE hash_arg,
                    texplay_sync sync_mode, bool primary, action_struct * payload)
{
    action_struct cur;
    rgba old_color;
    int y1;
    bool spanLeft, spanRight;

    if(!bound_by_rect(x, y, 0, 0, tex->width - 1, tex->height - 1)) return;

    /* NB: using XMAX_OOB etc since we dont know the drawing area yet; drawing area will be set by
       update_bounds() function in main loop */
    draw_prologue(&cur, tex, XMAX_OOB, YMAX_OOB, XMIN_OOB, YMIN_OOB, &hash_arg, sync_mode, primary, &payload);

    /* fill hates alpha_blend so let's turn it off */
    payload->pen.alpha_blend = false;
    
    old_color = get_pixel_color(tex, x, y);

    if(cmp_color(old_color, cur.color)) return;
    
    emptyStack();
    
    if(!push(x, y, tex->width - 1)) return;
    
    while(pop(&x, &y, tex->width - 1))
        {    
            y1 = y;
            while(y1 >= 0 && cmp_color(old_color, get_pixel_color(tex, x, y1))) y1--;
            y1++;
            spanLeft = spanRight = false;
            while(y1 < tex->height && cmp_color(old_color, get_pixel_color(tex, x, y1)) )
                {
                    set_pixel_color_with_style(payload, tex, x, y1);

                    /* update the drawing rectangle */
                    update_bounds(payload, x, y1, x, y1);

                    if(!spanLeft && x > 0 && cmp_color(old_color, get_pixel_color(tex, x - 1, y1))) 
                        {
                            if(!push(x - 1, y1, tex->width - 1)) return;
                            spanLeft = true;
                        }

                    else if(spanLeft && !cmp_color(old_color, get_pixel_color(tex, x - 1, y1)))
                        {
                            spanLeft = false;
                        }

                    if(!spanRight && x < tex->width - 1 && cmp_color(old_color,
                                                                     get_pixel_color(tex, x + 1, y1))) 
                        {
                            if(!push(x + 1, y1, tex->width - 1)) return;
                            spanRight = true;
                        }

                    else if(spanRight && x < tex->width - 1 && !cmp_color(old_color,get_pixel_color(tex, x + 1, y1)))
                        {
                            spanRight = false;
                        } 
                    y1++;
                }
        }
    draw_epilogue(&cur, tex, primary);
}