?? stk.c
字號:
/* * Copyright (c) 1997-2003 Erez Zadok * Copyright (c) 2001-2003 Stony Brook University * Copyright (c) 1997-2000 Columbia University * * For specific licensing information, see the COPYING file distributed with * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING. * * This Copyright notice must be kept intact and distributed with all * fistgen sources INCLUDING sources generated by fistgen. *//* * stk.c: stack manipulation routines * Fistgen sources. */#ifdef HAVE_CONFIG_H# include <config.h>#endif /* HAVE_CONFIG_H */typedef struct stk_cell { int val; struct stk_cell *next;} stk_cell_t;static stk_cell_t *cpp_stack = NULL;voidstk_init(void){ if (cpp_stack) fprintf(stderr, "internal error: stack is not empty!\n"); cpp_stack = NULL; /* XXX: free it if not NULL */}/* pust a new element onto the stack */voidstk_push(int val){ stk_cell_t *tmp = malloc(sizeof(stk_cell_t)); if (!tmp) { fprintf(stderr, "no more memory for stack cells\n"); exit(1); } tmp->val = val; tmp->next = cpp_stack; cpp_stack = tmp;}/* return top element in the stack, or -1 of empty */intstk_pop(void){ stk_cell_t *tmp; int val; if (!cpp_stack) { fprintf(stderr, "cannot pop an empty stack. cpp error.\n"); return -1; } tmp = cpp_stack; cpp_stack = cpp_stack->next; val = tmp->val; free(tmp); tmp = NULL; return val;}/* * Return value at top of stack. * TRUE/FALSE or -1 if stack is empty. */intstk_top(void){ if (!cpp_stack) { fprintf(stderr, "stk_top: state stack is empty!\n"); return -1; } return cpp_stack->val;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -