Exemple #1
0
int main(int argc, char **argv)
{
	GOptionContext *pc;
	char *line;
	struct irc_network_info *info;
	char *path;
	GOptionEntry options[] = {
		{ NULL }
	};

	pc = g_option_context_new("");
	g_option_context_add_main_entries(pc, options, NULL);
	if(!g_option_context_parse(pc, &argc, &argv, NULL))
		return 1;

	if (argc < 3) {
		fprintf(stderr, "Usage: %s <directory> <name>\n", argv[0]);
		return 1;
	}

	info = g_new0(struct irc_network_info, 1);

	state = network_state_init("nick", "username", "hostname");

	g_assert(state != NULL);

	markers = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
									(GDestroyNotify)linestack_free_marker);

	path = g_build_filename(argv[1], argv[2], NULL);

	ctx = create_linestack(path, TRUE, state);

	g_free(path);

	atexit(freels);

	if (ctx == NULL) {
		fprintf(stderr, "Unable to open linestack context\n");
		return 1;
	}

	while (1) {
		gint cargc;
		GError *error = NULL;
		gchar **cargv = NULL;
		int i;

		line = readline("linestack> ");	

		if (line == NULL)
			return 0;

		if (!g_shell_parse_argv(line, &cargc, &cargv, &error)) {
			fprintf(stderr, "Error parsing: %s\n", error->message);
			g_error_free(error);
			goto next;
		}

		if (cargc == 0) {
			goto next;
		}

		for (i = 0; cmds[i].name; i++) {
			if (!strcmp(cmds[i].name, cargv[0])) {
				cmds[i].handler(cargc, cargv);
				goto next;
			}
		}

		fprintf(stderr, "Unknown command `%s'\n", cargv[0]);

next:
		g_strfreev(cargv);

		free(line);
	}
	g_option_context_free(pc);

	return 0;
}
Exemple #2
0
int main() {

    int num,i,j=0;
    char cpush[]="Push";
    char cpop[]="Pop";
    char order[100][500];
    int ele[100];
    x temp;
    linestack *s;
    s=create_linestack();


    scanf("%d",&num);
    for(i=0; i<2*num; i++) {
        scanf("%s",order[i]);
        if(strcmp(order[i],cpush)==0) {

            scanf("%d",&ele[i]);
            temp.element=ele[i];
            temp.times=1;
            push(temp,s);
        }

        if(strcmp(order[i],cpop)==0) {
            temp=pop(s);
            if(temp.times==1) {
                temp.times=2;
                push(temp,s);
            }

            else if(temp.times==2) {
                //		printf("%d\n",temp.element);
                ele[j++]=temp.element;
//			printf("%d\n",ele[j-1]);
                while(s->data[s->top].times==2) {
                    //				printf("%d\n",s->data[s->top].element);
                    ele[j++]=s->data[s->top].element;
                    pop(s);
                }
                if(s->top!=-1) {
                    s->data[s->top].times=2;
                }
            }

        }

    }

    for(i=0; i<j; i++) {
        printf("%d ",ele[i]);
    }
    while(s->top!=-1) {
        printf("%d",s->data[s->top].element);
        pop(s);
        if(s->top!=-1) {
            printf(" ");
        }
    }

    /*
    	for(i=0;i<2*num;i++){
    		printf("%s %d\n",order[i],ele[i]);
    	}
    */

}