File: pf_main.c

package info (click to toggle)
pforth 1%3A2.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 904 kB
  • sloc: ansic: 6,283; makefile: 410
file content (151 lines) | stat: -rw-r--r-- 3,724 bytes parent folder | download
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/* @(#) pf_main.c 98/01/26 1.2 */
/***************************************************************
** Forth based on 'C'
**
** main() routine that demonstrates how to call PForth as
** a module from 'C' based application.
** Customize this as needed for your application.
**
** Author: Phil Burk
** Copyright 1994 3DO, Phil Burk, Larry Polansky, David Rosenboom
**
** Permission to use, copy, modify, and/or distribute this
** software for any purpose with or without fee is hereby granted.
**
** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
** THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
** CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
** FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
** CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
** OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**
***************************************************************/

#if (defined(PF_NO_STDIO) || defined(PF_EMBEDDED))
    #define NULL  ((void *) 0)
    #define ERR(msg) /* { printf msg; } */
#else
    #include <stdio.h>
    #define ERR(msg) { printf msg; }
#endif

#include "pforth.h"

#ifndef PF_DEFAULT_DICTIONARY
#define PF_DEFAULT_DICTIONARY "pforth.dic"
#endif

#ifdef __MWERKS__
    #include <console.h>
    #include <sioux.h>
#endif

#ifndef TRUE
#define TRUE (1)
#define FALSE (0)
#endif

#ifdef PF_EMBEDDED
int main( void )
{
    char IfInit = 0;
    const char *DicName = NULL;
    const char *SourceName = NULL;
    pfMessage("\npForth Embedded\n");
    return pfDoForth( DicName, SourceName, IfInit);
}
#else

int main( int argc, char **argv )
{
#ifdef PF_STATIC_DIC
    const char *DicName = NULL;
#else /* PF_STATIC_DIC */
    const char *DicName = PF_DEFAULT_DICTIONARY;
#endif /* !PF_STATIC_DIC */

    const char *SourceName = NULL;
    char IfInit = FALSE;
    char *s;
    cell_t i;
    ThrowCode Result;

/* For Metroworks on Mac */
#ifdef __MWERKS__
    argc = ccommand(&argv);
#endif

    pfSetQuiet( FALSE );
/* Parse command line. */
    for( i=1; i<argc; i++ )
    {
        s = argv[i];

        if( *s == '-' )
        {
            char c;
            s++; /* past '-' */
            c = *s++;
            switch(c)
            {
            case 'i':
                IfInit = TRUE;
                DicName = NULL;
                break;

            case 'q':
                pfSetQuiet( TRUE );
                break;

            case 'd':
                if( *s != '\0' ) DicName = s;
                /* Allow space after -d (Thanks Aleksej Saushev) */
                /* Make sure there is another argument. */
                else if( (i+1) < argc )
                {
                    DicName = argv[++i];
                }
                if (DicName == NULL || *DicName == '\0')
                {
                    DicName = PF_DEFAULT_DICTIONARY;
                }
                break;

            default:
                ERR(("Unrecognized option!\n"));
                ERR(("pforth {-i} {-q} {-dfilename.dic} {sourcefilename}\n"));
                Result = 1;
                goto on_error;
                break;
            }
        }
        else
        {
            SourceName = s;
        }
    }
/* Force Init */
#ifdef PF_INIT_MODE
    IfInit = TRUE;
    DicName = NULL;
#endif

#ifdef PF_UNIT_TEST
    if( (Result = pfUnitTest()) != 0 )
    {
        ERR(("pForth stopping on unit test failure.\n"));
        goto on_error;
    }
#endif

    Result = pfDoForth( DicName, SourceName, IfInit);

on_error:
    return (int)Result;
}

#endif  /* PF_EMBEDDED */