File: int_stack.c

package info (click to toggle)
foma 1%3A0.9.18%2Br243-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 876 kB
  • sloc: ansic: 13,797; lex: 1,390; yacc: 315; python: 274; perl: 147; makefile: 103; javascript: 42
file content (96 lines) | stat: -rw-r--r-- 2,219 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*   Foma: a finite-state toolkit and library.                                 */
/*   Copyright © 2008-2015 Mans Hulden                                         */

/*   This file is part of foma.                                                */

/*   Licensed under the Apache License, Version 2.0 (the "License");           */
/*   you may not use this file except in compliance with the License.          */
/*   You may obtain a copy of the License at                                   */

/*      http://www.apache.org/licenses/LICENSE-2.0                             */

/*   Unless required by applicable law or agreed to in writing, software       */
/*   distributed under the License is distributed on an "AS IS" BASIS,         */
/*   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  */
/*   See the License for the specific language governing permissions and       */
/*   limitations under the License.                                            */

#include <stdio.h>
#include <stdlib.h>
#include "foma.h"

#define MAX_STACK 2097152
#define MAX_PTR_STACK 2097152

static int a[MAX_STACK];
static int top = -1;

static void *ptr_stack[MAX_PTR_STACK];
static int ptr_stack_top = -1;

int ptr_stack_isempty() {
    return ptr_stack_top == -1;
}

void ptr_stack_clear() {
    ptr_stack_top = -1;
}

void *ptr_stack_pop() {
    return ptr_stack[ptr_stack_top--];
}

int ptr_stack_isfull() {
    return (ptr_stack_top == (MAX_PTR_STACK - 1));
}

void ptr_stack_push(void *ptr) {
    if (ptr_stack_isfull()) {
        fprintf(stderr, "Pointer stack full!\n");
        exit(1);
    }
    ptr_stack[++ptr_stack_top] = ptr;
}


int int_stack_isempty() {
  return top == -1;
}

void int_stack_clear() {
  top = -1;
}

int int_stack_find (int entry) {
  int i;
  if (int_stack_isempty()) {
    return 0;
  }
  for(i = 0; i <= top ; i++) {
    if (entry == a[i]) {
      return 1;
    }
  }
  return 0;
}

int int_stack_size () {
  return (top + 1);
}

void int_stack_push(int c) {
  if (int_stack_isfull()) {
    fprintf(stderr, "Stack full!\n");
    exit(1);
  }
  a[++top] = c;
}


int int_stack_pop() {
  return a[top--];
}

int int_stack_isfull() {
  return (top == (MAX_STACK - 1));
}