Exemplo n.º 1
0
BOOL xyzsh_eval(int* rcode, char* cmd, char* source_name, fXyzshJobDone xyzsh_job_done_, sObject* nextin, sObject* nextout, int argc, char** argv, sObject* current_object)
{
    string_put(gErrMsg, "");

    xyzsh_job_done = xyzsh_job_done_;

    stack_start_stack();

    sObject* block = BLOCK_NEW_STACK();
    int sline = 1;
    if(parse(cmd, source_name, &sline, block, NULL)) {
        xyzsh_set_signal();

        sObject* fun = FUN_NEW_STACK(NULL);
        sObject* stackframe = UOBJECT_NEW_GC(8, gXyzshObject, "_stackframe", FALSE);
        vector_add(gStackFrames, stackframe);
        //uobject_init(stackframe);
        SFUN(fun).mLocalObjects = stackframe;

        sObject* argv2 = VECTOR_NEW_GC(16, FALSE);
        int i;
        for(i=0; i<argc; i++) {
            vector_add(argv2, STRING_NEW_GC(argv[i], FALSE));
        }
        uobject_put(SFUN(fun).mLocalObjects, "ARGV", argv2);

        if(!run(block, nextin, nextout, rcode, current_object, fun)) {
            xyzsh_restore_signal_default();
            (void)vector_pop_back(gStackFrames);

            stack_end_stack();

            /// wait background job
            xyzsh_wait_background_job();

            return FALSE;
        }
        xyzsh_restore_signal_default();

        (void)vector_pop_back(gStackFrames);
        stack_end_stack();
    }
    else {
        stack_end_stack();

        /// wait background job
        xyzsh_wait_background_job();

        return FALSE;
    }

    /// wait background job
    xyzsh_wait_background_job();

    return TRUE;
}
int main() {
    struct vector_t myVector, secondVector;

    vector_init(&myVector);

    vector_push_back(&myVector,3);
    vector_push_back(&myVector,1);
    vector_push_back(&myVector,4);
    vector_push_back(&myVector,1);
    vector_push_back(&myVector,5);
    vector_push_back(&myVector,9);
    vector_push_back(&myVector,2);
    vector_push_back(&myVector,6);

    vector_copy(&myVector, &secondVector);
    printf("Size of copied vector: %d\n", vector_get_size(secondVector));

    printf("Size: %d\n", vector_get_size(myVector));
    printf("Pop: %d\n", vector_pop_back(&myVector));
    printf("Pop: %d\n", vector_pop_back(&myVector));
    printf("Pop: %d\n", vector_pop_back(&myVector));
    printf("Pop: %d\n", vector_pop_back(&myVector));
    printf("Pop: %d\n", vector_pop_back(&myVector));
    printf("Size: %d\n", vector_get_size(myVector));
    printf("Pop: %d\n", vector_pop_back(&myVector));
    printf("Pop: %d\n", vector_pop_back(&myVector));
    printf("Pop: %d\n", vector_pop_back(&myVector));
    printf("Size: %d\n", vector_get_size(myVector));

    vector_destroy(&myVector);
    return 0;
}
int main() 
{
	struct vector_t vec;
	struct vector_t vec2;
	int i;
	printf("Original vector test\n");
	vector_init(&vec);
	printf("Pushing into vector\n");

	for(i=0; i<10; i++)
	{
		vector_push_back(&vec, i);
		printf("Index: %d\n", vector_get_size(vec));
	}

	printf("Popping out of vector\n");

	for(i=0; i<10; i++)
	{
		vector_pop_back(&vec);
		printf("Index: %d\n", vector_get_size(vec));
	}

	vector_copy(&vec, &vec2);
	vector_destroy(&vec);

	printf("Copied vector test\n");
	printf("Pushing in vector\n");

	for(i=0; i<10; i++)
	{
		vector_push_back(&vec2, i);
		printf("Index: %d\n", vector_get_size(vec2));
	}

	printf("Popping out of vector\n");

	for(i=0; i<10; i++)
	{
		vector_pop_back(&vec2);
		printf("Index: %d\n", vector_get_size(vec2));
	}
	
	vector_destroy(&vec2);
return 0;
}
int main() {
	struct vector_t x;
	vector_init(&x);
	vector_push_back(&x, 1);
	vector_push_back(&x, 2);
	vector_push_back(&x, 3);
	vector_pop_back(&x);
	vector_resize(&x);
	vector_at(x, 2);

	struct vector_t y;
	vector_copy(&x, &y);
	vector_pop_back(&y);
	vector_pop_back(&y);
	if (vector_get_size == 0)
		vector_destroy(&y);

	return 0;
}
int main()
{
    struct vector_t vect;
    vector_init(&vect);
    int i,mysterious_number;
    for(i=0;i<43;i++) vector_push_back(&vect,i);
    mysterious_number = vector_at(vect,vector_get_size(vect)-1);
    printf( "%d %d\n" , vector_pop_back(&vect) , mysterious_number );
    printf("LOL! MAGIK!\n");
    return 0;
}
Exemplo n.º 6
0
/**
 * Delete the element at the begin of stack.
 */
void stack_pop(cstl_stack_t* psk_stack)
{
    assert(psk_stack != NULL);

#if defined (CSTL_STACK_VECTOR_SEQUENCE)
    vector_pop_back(&psk_stack->_t_sequence);
#elif defined (CSTL_STACK_LIST_SEQUENCE)
    list_pop_back(&psk_stack->_t_sequence);
#else
    deque_pop_back(&psk_stack->_t_sequence);
#endif
}
Exemplo n.º 7
0
void xyzsh_opt_c(char* cmd, char** argv, int argc)
{
    stack_start_stack();
    int rcode = 0;
    sObject* block = BLOCK_NEW_STACK();
    int sline = 1;
    if(parse(cmd, "xyzsh", &sline, block, NULL)) {
        xyzsh_set_signal_optc();

        sObject* fun = FUN_NEW_STACK(NULL);
        sObject* stackframe = UOBJECT_NEW_GC(8, gXyzshObject, "_stackframe", FALSE);
        vector_add(gStackFrames, stackframe);
        //uobject_init(stackframe);
        SFUN(fun).mLocalObjects = stackframe;

        sObject* argv2 = VECTOR_NEW_GC(16, FALSE);
        int i;
        for(i=0; i<argc; i++) {
            vector_add(argv2, STRING_NEW_GC(argv[i], FALSE));
        }
        uobject_put(SFUN(fun).mLocalObjects, "ARGV", argv2);

        if(!run(block, gStdin, gStdout, &rcode, gRootObject, fun)) {
            if(rcode == RCODE_BREAK) {
                fprintf(stderr, "invalid break. Not in a loop\n");
            }
            else if(rcode & RCODE_RETURN) {
                fprintf(stderr, "invalid return. Not in a function\n");
            }
            else if(rcode == RCODE_EXIT) {
            }
            else {
                fprintf(stderr, "run time error\n");
                fprintf(stderr, "%s", string_c_str(gErrMsg));
            }
        }
        (void)vector_pop_back(gStackFrames);
        xyzsh_restore_signal_default();
    }
    else {
        fprintf(stderr, "parser error\n");
        fprintf(stderr, "%s", string_c_str(gErrMsg));
    }

    if(rcode != 0) {
        fprintf(stderr, "return code is %d\n", rcode);
    }
    stack_end_stack();
}
Exemplo n.º 8
0
void test_vector()
{
   size_t arr[10], arr2[10];
   size_t i, j;
   vector vec;

   j = 200;

   vector_init(&vec, &malloc, &free);

   for (i = 0; i < 10; ++i)
   {
      arr[i] = i;

      vector_push_back(&vec, &arr[i]);

   }

   for (i = 0; i < 10; ++i)
   {
      arr2[i] = i + 10;

      vector_push_back(&vec, &arr2[i]);

   }

   vector_insert(&vec, &j, vec.size);
   vector_remove(&vec, 0);

   printf("-----\nVector testing\n-----\nSize: %d\nMax size: %d\nContents: ", vector_size(&vec), vector_max_size(&vec));

   for (i = 0; i < 20; ++i) printf("%d ", *(size_t*)vector_pop_back(&vec));

   vector_push_back(&vec, &j);

   printf("\nFront: %d\nBack: %d\n", *(size_t*)vector_front(&vec), *(size_t*)vector_back(&vec));

   vector_clear(&vec);

   printf("Vector cleared\nSize: %d\n", vec.size);

   vector_free(&vec);

   printf("\n");

}
Exemplo n.º 9
0
void priority_queue_pop(priority_queue_t* pt_pqueue)
{
    assert(pt_pqueue != NULL);

    if(pt_pqueue->_t_binary_op == NULL)
    {
        algo_pop_heap(
            vector_begin(&pt_pqueue->_t_vector), vector_end(&pt_pqueue->_t_vector));
    }
    else
    {
        algo_pop_heap_if(
            vector_begin(&pt_pqueue->_t_vector), vector_end(&pt_pqueue->_t_vector),
            pt_pqueue->_t_binary_op);
    }
    vector_pop_back(&pt_pqueue->_t_vector);
}
Exemplo n.º 10
0
static void remove_clients(vector_t* v, const char* pfx)
{
    void* tmp;
    size_t tmp_len;
    while (vector_pop_back(v, &tmp, &tmp_len))
    {
        client_t* client;
        char ip[16];
        struct in_addr a;
        active_vector_get(&this.clients, (size_t)tmp, (void**)&client, &tmp_len);
        a.s_addr = client->remote_ip;
        sprintf(ip, "%s", inet_ntoa(a));
        SYSLOG(LOG_INFO, "%s: %s", pfx, ip);
        close(client->fd);
        hash_free(&client->recv_table);
        active_vector_del(&this.clients, (size_t)tmp);
    }
}
int main() {
    struct vector_t vec;
    vector_init(&vec);
    vector_push_back(&vec, 5);
    int i, value;
    for (i = 0; i < vector_get_size(vec); i++)
    {
        value = vector_at(vec, i);
        printf("%d \n", value);
    }
    
    value = vector_pop_back(&vec);
    printf("%d\n", value);
    
    value = vector_at(vec, 456);
    printf("%d\n", value);
    vector_destroy(&vec);
    return 0;
}
Exemplo n.º 12
0
void config_content_pop_path_stack( config_content_type * content ) {
  vector_pop_back( content->path_elm_stack );
}
Exemplo n.º 13
0
void stack_pop(stack *s)
{
	vector_pop_back(&s->storage);
}
Exemplo n.º 14
0
void xyzsh_readline_interface(char* cmdline, int cursor_point, char** argv, int argc, BOOL exit_in_spite_ofjob_exist, BOOL welcome_msg)
{
    /// start interactive shell ///
    xyzsh_job_done = main_xyzsh_job_done;

    if(welcome_msg) {
        char* version = getenv("XYZSH_VERSION");
        printf("-+- Welcome to xyzsh %s -+-\n", version);
        printf("run \"help\" command to see usage\n");
    }

    char* buf;
    BOOL first = TRUE;
    while(1) {
        /// prompt ///
        if(first) {
            buf = ALLOC run_editline(cmdline, cursor_point);
            first = FALSE;
        }
        else {
            buf = ALLOC run_editline(NULL, -1);
        }

        /// run ///
        if(buf == NULL) {
            if(exit_in_spite_ofjob_exist) {
                break;
            }
            else {
                if(vector_count(gJobs) > 0) {
                    fprintf(stderr,"\njobs exist\n");
                }
                else {
                    break;
                }
            }
        }
        else if(*buf) {
            stack_start_stack();
            int rcode = 0;
            sObject* block = BLOCK_NEW_STACK();
            int sline = 1;
            if(parse(buf, "xyzsh", &sline, block, NULL)) {
                xyzsh_set_signal();

                sObject* fun = FUN_NEW_STACK(NULL);
                sObject* stackframe = UOBJECT_NEW_GC(8, gXyzshObject, "_stackframe", FALSE);
                vector_add(gStackFrames, stackframe);
                //uobject_init(stackframe);
                SFUN(fun).mLocalObjects = stackframe;

                sObject* argv2 = VECTOR_NEW_GC(16, FALSE);
                int i;
                for(i=0; i<argc; i++) {
                    vector_add(argv2, STRING_NEW_GC(argv[i], FALSE));
                }
                uobject_put(SFUN(fun).mLocalObjects, "ARGV", argv2);

                if(!run(block, gStdin, gStdout, &rcode, gCurrentObject, fun)) {
                    if(rcode == RCODE_BREAK) {
                        fprintf(stderr, "invalid break. Not in a loop\n");
                    }
                    else if(rcode & RCODE_RETURN) {
                        fprintf(stderr, "invalid return. Not in a function\n");
                    }
                    else if(rcode == RCODE_EXIT) {
                        (void)vector_pop_back(gStackFrames);
                        stack_end_stack();
                        FREE(buf);
                        break;
                    }
                    else {
                        fprintf(stderr, "run time error\n");
                        fprintf(stderr, "%s", string_c_str(gErrMsg));
                    }
                }
                (void)vector_pop_back(gStackFrames);
            }
            else {
                fprintf(stderr, "parser error\n");
                fprintf(stderr, "%s", string_c_str(gErrMsg));
            }

            if(rcode != 0) {
                fprintf(stderr, "return code is %d\n", rcode);
            }
            stack_end_stack();
        }

        /// wait background job
        xyzsh_wait_background_job();

        FREE(buf);
    }
}
Exemplo n.º 15
0
// EOF --> rcode == -2
// errors --> rcode == -1
BOOL xyzsh_readline_interface_onetime(int* rcode, char* cmdline, int cursor_pos, char* source_name, char** argv, int argc, fXyzshJobDone xyzsh_job_done_)
{
    /// start interactive shell ///
    xyzsh_job_done = xyzsh_job_done_;

    /// edit line ///
    char* buf = ALLOC run_editline(cmdline, cursor_pos);

    /// run ///
    if(buf == NULL) {
        *rcode = -2;

        /// wait background job
        xyzsh_wait_background_job();
    }
    else if(*buf) {
        stack_start_stack();
        sObject* block = BLOCK_NEW_STACK();
        int sline = 1;
        if(parse(buf, "xyzsh", &sline, block, NULL)) {
            xyzsh_set_signal();

            sObject* fun = FUN_NEW_STACK(NULL);
            sObject* stackframe = UOBJECT_NEW_GC(8, gXyzshObject, "_stackframe", FALSE);
            vector_add(gStackFrames, stackframe);
            //uobject_init(stackframe);
            SFUN(fun).mLocalObjects = stackframe;

            sObject* argv2 = VECTOR_NEW_GC(16, FALSE);
            int i;
            for(i=0; i<argc; i++) {
                vector_add(argv2, STRING_NEW_GC(argv[i], FALSE));
            }
            uobject_put(SFUN(fun).mLocalObjects, "ARGV", argv2);

            if(!run(block, gStdin, gStdout, rcode, gCurrentObject, fun)) {
                xyzsh_restore_signal_default();

                if(*rcode == RCODE_BREAK) {
                    fprintf(stderr, "invalid break. Not in a loop\n");
                }
                else if(*rcode & RCODE_RETURN) {
                    fprintf(stderr, "invalid return. Not in a function\n");
                }
                else if(*rcode == RCODE_EXIT) {
                }
                else {
                    fprintf(stderr, "run time error\n");
                    fprintf(stderr, "%s", string_c_str(gErrMsg));
                }

                if(*rcode != 0) {
                    fprintf(stderr, "return code is %d\n", *rcode);
                }
                (void)vector_pop_back(gStackFrames);
                stack_end_stack();

                /// wait background job
                xyzsh_wait_background_job();

                FREE(buf);

                return FALSE;
            }
            (void)vector_pop_back(gStackFrames);
        }
        else {
            xyzsh_restore_signal_default();

            fprintf(stderr, "parser error\n");
            fprintf(stderr, "%s", string_c_str(gErrMsg));

            if(*rcode != 0) {
                fprintf(stderr, "return code is %d\n", *rcode);
            }
            stack_end_stack();

            /// wait background job
            xyzsh_wait_background_job();

            FREE(buf);

            return FALSE;
        }

        if(*rcode != 0) {
            fprintf(stderr, "return code is %d\n", *rcode);
        }
        stack_end_stack();

        /// wait background job
        xyzsh_wait_background_job();

        FREE(buf);
    }

    return TRUE;
}
Exemplo n.º 16
0
static ALLOC char* run_editline(char* text, int cursor_pos)
{
    stack_start_stack();

    char* buf;

    char* prompt;
    if(gPrompt) {
        xyzsh_set_signal();

        sObject* fun = FUN_NEW_STACK(NULL);
        sObject* stackframe = UOBJECT_NEW_GC(8, gXyzshObject, "_stackframe", FALSE);
        vector_add(gStackFrames, stackframe);
        //uobject_init(stackframe);
        SFUN(fun).mLocalObjects = stackframe;

        sObject* nextout = FD_NEW_STACK();

        int rcode;
        if(!run(gPrompt, gStdin, nextout, &rcode, gCurrentObject, fun)) {
            if(rcode == RCODE_BREAK) {
                fprintf(stderr, "invalid break. Not in a loop\n");
            }
            else if(rcode & RCODE_RETURN) {
                fprintf(stderr, "invalid return. Not in a function\n");
            }
            else if(rcode == RCODE_EXIT) {
                fprintf(stderr, "invalid exit. In the prompt\n");
            }
            else {
                fprintf(stderr, "run time error\n");
                fprintf(stderr, "%s", string_c_str(gErrMsg));
            }
        }

        (void)vector_pop_back(gStackFrames);

        prompt = SFD(nextout).mBuf;
    }
    else {
        prompt = " > ";
    }

    char* rprompt;
    if(gRPrompt) {
        sObject* fun = FUN_NEW_STACK(NULL);
        sObject* stackframe = UOBJECT_NEW_GC(8, gXyzshObject, "_stackframe", FALSE);
        vector_add(gStackFrames, stackframe);
        //uobject_init(stackframe);
        SFUN(fun).mLocalObjects = stackframe;

        sObject* nextout2 = FD_NEW_STACK();

        int rcode;
        if(!run(gRPrompt, gStdin, nextout2, &rcode, gCurrentObject, fun)) {
            if(rcode == RCODE_BREAK) {
                fprintf(stderr, "invalid break. Not in a loop\n");
            }
            else if(rcode & RCODE_RETURN) {
                fprintf(stderr, "invalid return. Not in a function\n");
            }
            else if(rcode == RCODE_EXIT) {
                fprintf(stderr, "invalid exit. In the prompt\n");
            }
            else {
                fprintf(stderr, "run time error\n");
                fprintf(stderr, "%s", string_c_str(gErrMsg));
            }
        }
        (void)vector_pop_back(gStackFrames);

        rprompt = SFD(nextout2).mBuf;
    }
    else {
        rprompt = NULL;
    }

    mreset_tty();
    buf = ALLOC editline(prompt, rprompt, text, cursor_pos);

    stack_end_stack();

    return ALLOC buf;
}
Exemplo n.º 17
0
char * stringlist_pop( stringlist_type * stringlist) {
  return vector_pop_back( stringlist->strings );
}
Exemplo n.º 18
0
void stack_pop(Stack* stack)
{
  vector_pop_back(stack->elems);
}