int main(int argc, char * argv[]) { /* * use example : * make * ./reader https://pilotweb.nas.faa.gov/common/nat.html */ if (argc != 2) return EXIT_FAILURE; char * page = read_page(argv[1]); if (page == NULL) return EXIT_FAILURE; stack_t * stack = get_tracks(page); char * track = (char *)s_pop(&stack); while(track != NULL) { printf("%s\n", track); free(track); track = (char *)s_pop(&stack); } free(page); return EXIT_SUCCESS; }
struct node* b_pop(struct stack *balancer) { struct stack *s = b_current_stack(balancer); if (s == NULL) return NULL; struct node *n = s_pop(s); if (s->n_items == 0) { free(s_pop(balancer)); } return n; }
void s_destroy(Stack *s) { // destroys the stack altogether, a node at a time. // pop everything off the stack S_Node *head; for (head = s_pop(s); head != NULL; head = s_pop(s)) { ; } // destroy the stack itself free(s); }
void s_destroy(struct Stack* s) { int n; for(n = s->length; n > 0; n--) { s_pop(s); } free(s); }
int main(void) { int i, val; for (i = 0; i < STACK_LIMIT; i+=2) s_push(i); for (i = 0; i < STACK_LIMIT; i++) { if(s_pop(&val) == 0) printf("POP: %d\n", val); } return 0; }
void copy_recursive() { struct Stack* paths; DIR *dir; struct dirent *entry; const String d_name; int dir_count; dir_count = 0; paths = malloc(sizeof (struct Stack)); s_create(paths); s_push(basename(src), paths); strcpy(src, dirname(src)); strcpy(dest, dirname(dest)); printf("Source: %s\nTarget: %s\n\n", src, dest); while(!s_isEmpty(paths)) { strcat(src, "/"); strcat(src, s_peek(paths)); s_pop(paths); if((dir = opendir(src))) { while((entry = readdir(dir))) { d_name = entry->d_name; if(entry->d_type & DT_DIR) { printf("Found FOLDER: %s\n", d_name); if (strcmp(d_name, "..") != 0 && strcmp(d_name, ".") != 0) { s_push(d_name, paths); dir_count++; } } else if (entry->d_type & DT_REG) { printf("Found FILE: %s\n", d_name); } } if (!closedir(dir)) { printf("Time to copy\n"); } else { fprintf(stderr, "Could not close '%s': %s\n", src, strerror(errno)); exit(EXIT_FAILURE); } } else { fprintf(stderr, "Cannot open %s: %s\n", src, strerror(errno)); exit(EXIT_FAILURE); } if(dir_count) { strcpy(src, dirname(src)); dir_count--; } } }
int PyParser_AddToken(parser_state *ps, int type, char *str, int lineno, int col_offset, int *expected_ret) { int ilabel; int err; D(printf("Token %s/'%s' ... ", _PyParser_TokenNames[type], str)); /* Find out which label this token is */ ilabel = classify(ps, type, str); if (ilabel < 0) return E_SYNTAX; /* Loop until the token is shifted or an error occurred */ for (;;) { /* Fetch the current dfa and state */ dfa *d = ps->p_stack.s_top->s_dfa; state *s = &d->d_state[ps->p_stack.s_top->s_state]; D(printf(" DFA '%s', state %d:", d->d_name, ps->p_stack.s_top->s_state)); /* Check accelerator */ if (s->s_lower <= ilabel && ilabel < s->s_upper) { int x = s->s_accel[ilabel - s->s_lower]; if (x != -1) { if (x & (1<<7)) { /* Push non-terminal */ int nt = (x >> 8) + NT_OFFSET; int arrow = x & ((1<<7)-1); dfa *d1 = PyGrammar_FindDFA( ps->p_grammar, nt); if ((err = push(&ps->p_stack, nt, d1, arrow, lineno, col_offset)) > 0) { D(printf(" MemError: push\n")); return err; } D(printf(" Push ...\n")); continue; } /* Shift the token */ if ((err = shift(&ps->p_stack, type, str, x, lineno, col_offset)) > 0) { D(printf(" MemError: shift.\n")); return err; } D(printf(" Shift.\n")); /* Pop while we are in an accept-only state */ while (s = &d->d_state [ps->p_stack.s_top->s_state], s->s_accept && s->s_narcs == 1) { D(printf(" DFA '%s', state %d: " "Direct pop.\n", d->d_name, ps->p_stack.s_top->s_state)); #ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD #if 0 if (d->d_name[0] == 'i' && strcmp(d->d_name, "import_stmt") == 0) future_hack(ps); #endif #endif s_pop(&ps->p_stack); if (s_empty(&ps->p_stack)) { D(printf(" ACCEPT.\n")); return E_DONE; } d = ps->p_stack.s_top->s_dfa; } return E_OK; } }
int PyParser_AddToken(register parser_state *ps, register int type, char *str, int lineno, int *expected_ret) { register int ilabel; int err; D(printf("Token %s/'%s' ... ", _PyParser_TokenNames[type], str)); /* Find out which label this token is */ ilabel = classify(ps, type, str); if (ilabel < 0) return E_SYNTAX; /* Loop until the token is shifted or an error occurred */ for (;;) { /* Fetch the current dfa and state */ register dfa *d = ps->p_stack.s_top->s_dfa; register state *s = &d->d_state[ps->p_stack.s_top->s_state]; D(printf(" DFA '%s', state %d:", d->d_name, ps->p_stack.s_top->s_state)); /* Check accelerator */ if (s->s_lower <= ilabel && ilabel < s->s_upper) { register int x = s->s_accel[ilabel - s->s_lower]; if (x != -1) { if (x & (1<<7)) { /* Push non-terminal */ int nt = (x >> 8) + NT_OFFSET; int arrow = x & ((1<<7)-1); dfa *d1 = PyGrammar_FindDFA( ps->p_grammar, nt); if ((err = push(&ps->p_stack, nt, d1, arrow, lineno)) > 0) { D(printf(" MemError: push\n")); return err; } D(printf(" Push ...\n")); continue; } /* Shift the token */ if ((err = shift(&ps->p_stack, type, str, x, lineno)) > 0) { D(printf(" MemError: shift.\n")); return err; } D(printf(" Shift.\n")); /* Pop while we are in an accept-only state */ while (s = &d->d_state [ps->p_stack.s_top->s_state], s->s_accept && s->s_narcs == 1) { D(printf(" DFA '%s', state %d: " "Direct pop.\n", d->d_name, ps->p_stack.s_top->s_state)); if (d->d_name[0] == 'i' && strcmp(d->d_name, "import_stmt") == 0) future_hack(ps); s_pop(&ps->p_stack); if (s_empty(&ps->p_stack)) { D(printf(" ACCEPT.\n")); return E_DONE; } d = ps->p_stack.s_top->s_dfa; } return E_OK; } } if (s->s_accept) { if (d->d_name[0] == 'i' && strcmp(d->d_name, "import_stmt") == 0) future_hack(ps); /* Pop this dfa and try again */ s_pop(&ps->p_stack); D(printf(" Pop ...\n")); if (s_empty(&ps->p_stack)) { D(printf(" Error: bottom of stack.\n")); return E_SYNTAX; } continue; } /* Stuck, report syntax error */ D(printf(" Error.\n")); if (expected_ret) { if (s->s_lower == s->s_upper - 1) { /* Only one possible expected token */ *expected_ret = ps->p_grammar-> g_ll.ll_label[s->s_lower].lb_type; } else *expected_ret = -1; } return E_SYNTAX; }