Exemple #1
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;
}
Exemple #2
0
int main(int argc, char *argv[])
{
	(void)argc; // we don't use argc, causes compiler not to warn us about it.
	
	// The output of this program may change over a series of runs due to:
	// https://en.wikipedia.org/wiki/Address_space_layout_randomization
	int i = 10;
	char *str1 = "hello world"; // string literals are stored in the text region of memory, not on the heap.
	char str2[] = "hello world"; // stored on stack

	// highest addresses contain memory used by the OS:
	printAddress("getenv", getenv("PATH"));
	printAddress("argv", argv);

	// The stack grows downward (the first address below is higher than the second address)
	printAddress("&i inside main (stack)", &i);
	addStack();
	printAddress("str2 inside main (stack)", str2);

	// String literals are stored in the .text section of memory (at the bottom of the stack)
	printAddress("str1 inside main (text)", str1);

	/* malloc() usually uses the heap to allocate memory. It does so by calling sbrk() to move the "program break" which is the top of the heap. Moving the "program break" to a higher value will give your process more memory. malloc() does this for you. If change the program break with sbrk(), you might break other functions that actually use malloc(). */
	printAddress("sbrk (heap)", sbrk(0));
	void *m = malloc(1024);
	printAddress("m (heap)", m);
	// NOTE: malloc() may use a few bytes for its own bookkeeping, 
	printAddress("sbrk after malloc (heap)", sbrk(0));
	free(m);
	// free()'ing memory doesn't necessarily move sbrk back down.
	printAddress("sbrk after free (heap)", sbrk(0));
	// instead, memory might be reused for future malloc()'s:
	m = malloc(10);
	void *m2 = malloc(100);
	printAddress("m (heap)", m);
	printAddress("m2 (heap)", m2);
	printAddress("sbrk after 2 more mallocs (heap)", sbrk(0));
	free(m);
	free(m2);

	/* malloc() uses mmap() when large areas of space are requested. */
	m = malloc(1024*128*50); // typically mmap is used for allocations larger than 128k
	printAddress("m (that may have been allocated with mmap) (mmap)", m);
	printAddress("sbrk after malloc (that may use mmap) (heap)", sbrk(0));
	free(m);

	printAddress("globalVar (text)", &globalVar);
	
	printAddress("printAddress (text)", printAddress);

	 // since we dynamically link to printf, its isn't defined until
	 // the linker links this program to libc at runtime. The address
	 // that is printed out is the address of the PLT for
	 // printf---which will then in-turn call printf().
	printAddress("printf PLT (text)", printf);

	return EXIT_SUCCESS;
}
Exemple #3
0
int main() {
	DStack_L stackL(SIZE_STACK),
			 stackSec(SIZE_STACK);
	if(fillingStack(stackL, stackSec) == false) {
		std::cout << "IMPOSSIBLE";
		return 0;
	}
	addStack(stackL, stackSec);
	char ch;
	while((ch = stackL.pop()) != '\n') {
		std::cout << ch;
	}
	return 0;
}
Exemple #4
0
void Resource::addStacks(Item* i){
	addStack(i->getStack());
	delete i;
}
DWORD LandScape::execV( LS_OPCODE _opcode, va_list _va )
{
   // reset the return status - individual functions will alter this if need be
   mExecStatus = EXEC_SUCCESS;
   mExecString[0] = '\0';
      
   switch( _opcode )
   {
      case LS_SEED: setSeed( va_arg(_va,DWORD) ); break;
      case LS_LOAD: return load( va_arg(_va,char*) );

      case LS_LOADM:
   		{
   			char * tmpCh = va_arg(_va,char*);
   			double tmpD = va_arg(_va,double);
   			return load(tmpCh, float(tmpD));
   		}
      case LS_SAVE: return save( va_arg(_va,char*) );
      case LS_CLEAR: clear(); break;
      case LS_PUSH: push( va_arg(_va,int)); break;
      case LS_POP:  pop(); break;
      case LS_GET:  return (DWORD)get( va_arg(_va,int) );
      case LS_SWAP: swap(); break;
      case LS_DUP:  dup(); break;
      case LS_ADD:  add( float(va_arg(_va,double)) ); break;
      case LS_SUB:  sub( float(va_arg(_va,double)) ); break;
      case LS_MUL:  mul( float(va_arg(_va,double)) ); break;
      case LS_DIV:  div( float(va_arg(_va,double)) ); break;
      case LS_EXP:  exp( float(va_arg(_va,double)) ); break;
      case LS_NEG:  neg(); break;
      case LS_CLR:  clr( float(va_arg(_va,double)) ); break;
      case LS_DIFF: diff(); break;

      case LS_NORMALIZE:
         {
            double i = va_arg(_va,double);
            double j = va_arg(_va,double);
            normalize( float(i), float(j) ); 
         }
         break;

      case LS_ADDS: addStack(); break;
      case LS_SUBS: subStack(); break;

      case LS_FLOOR:
         {
            double i = va_arg(_va,double);
            double j = va_arg(_va,double);
            double k = va_arg(_va,double);
            floor( float(i), float(j), float(k) );   
         }
         break;

      case LS_CEIL:
         {
            double i = va_arg(_va,double);
            double j = va_arg(_va,double);
            double k = va_arg(_va,double);
            ceil( i, j, k );   
         }
         break;

      case LS_CLIPMIN:  clipMin( float(va_arg(_va,double)) ); break;
      case LS_CLIPMAX:  clipMax( float(va_arg(_va,double)) ); break;
      case LS_ROT:   rot();   break;
      case LS_FLIPX: flipX(); break;
      case LS_FLIPY: flipY(); break;

      case LS_TERRAIN:
         {
         int    i = va_arg(_va,int);
         double j = va_arg(_va,double);
         if (i > 256)
         {
            terrain( 256, float(j) );
            size(i);
         }
         else
            terrain( i, float(j) );
         }
         break;

      case LS_PLASMA:
         {
         int    i = va_arg(_va,int);
         double j = va_arg(_va,double);
         if (i > 256)
         {
            plasma( 256, float(j) );
            size(i);
         }
         else
            plasma( i, float(j) );
         }
         break;

      case LS_SIZE: size( va_arg(_va,int) );  break;

      case LS_SLOPE:
         {
         double i = va_arg(_va,double);
         int    j = va_arg(_va,int);
         slope( i, float(j) );
         }
         break;

      case LS_SHAVE:
         {
         double i = va_arg(_va,double);
         double j = va_arg(_va,double);
         double k = va_arg(_va,double);
         shaveArea( float(i), float(j), float(k) );
         }
         break;
 
      case LS_CURVE:
         {
         double i = va_arg(_va,double);
         int    j = va_arg(_va,int);
         curve( float(i), j );
         }
         break;

      case LS_FFT:
         if (stack.size() > 1)
             fft( va_arg(_va,int) ); break;

      case LS_FILL_N:
        if (stack.size() > 1)
             fillNormal( float(va_arg(_va,double)) ); break;

      case LS_OVERLAY:
         {
         int    i = va_arg(_va,int);
         double j = va_arg(_va,double);
         overlay( i, float(j) );
         }
         break;

      case LS_ALPHABLEND:
         {
            int x = va_arg(_va, int);
            int y = va_arg(_va, int);
            alphablend(x, y);
         }
        break;

      case LS_BLEND:
         {
            int   i = va_arg(_va,int);
            int   j = va_arg(_va,int);
            blend( i, j );
         }

      case LS_SMOOTH:
         {
            double i = va_arg(_va,double);
            double j = va_arg(_va,double);
            smooth( float(i), float(j) ); 
         }
         break;

      case LS_TILE:  tile(); break;
      case LS_WRAP:  wrap(); break;

      case LS_CLAMP:
         {
         int    i = va_arg(_va,int);
         double j = va_arg(_va,double);
         clamp(i, float(j));
         }
         break;

      case LS_MASK:
         {
         int    i = va_arg(_va,int);
         double j = va_arg(_va,double);
         mask(i, float(j));
         }
         break;

      case LS_CRATER:
      case LS_PEAK:
      case LS_RING:
      case LS_FILLBASIN:
      case LS_LPFILTER:
      case LS_HPFILTER:
      case LS_BPFILTER:
      case LS_BRFILTER:
      case LS_FFLP:
      case LS_FFHP:
      case LS_FFBP:
      case LS_FFBR:
      default:
         break;
   }
   return NULL;
}
void UndoManager::addNewUndoStack()
{
    undoStacks.emplace_back(new QUndoStack);
    addStack(undoStacks.back().get());
}
Exemple #7
0
void Editor::stackAdded(QUndoStack *stack)
{
	addStack(stack);
}