source: git/Singular/febase.h @ 97a7b44

spielwiese
Last change on this file since 97a7b44 was a79a128, checked in by Olaf Bachmann <obachman@…>, 25 years ago
* use vsnprintf, instead of vsprintf, when possible * new string and print implementation * small bug fixes in iparith.cc git-svn-id: file:///usr/local/Singular/svn/trunk@2990 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 4.9 KB
Line 
1#ifndef FEBASE_H
2#define FEBASE_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/* $Id: febase.h,v 1.28 1999-04-17 14:58:46 obachman Exp $ */
7/*
8* ABSTRACT: basic i/o
9*/
10#include <stdio.h>
11#include <string.h>
12#include "structs.h"
13
14
15/*
16// These are our versions of fopen and fread They are very similar to
17// the usual fopen and fread, except that on reading, they always
18// convert "\r\n" into " \n" and "\r" into "\n".
19//
20// IMPORTANT: do only use myfopen and myfread when reading text,
21// do never use fopen and fread
22*/
23#ifndef unix
24FILE *myfopen(char *path, char *mode);
25#else
26#define myfopen fopen
27#endif
28size_t myfread(void *ptr, size_t size, size_t nmemb, FILE *stream);
29
30
31extern char*  feErrors;
32extern int    feErrorsLen;
33extern FILE*  feProtFile;
34extern FILE*  feFilePending; /*temp. storage for grammar.y */
35extern char   fe_promptstr[];
36extern int    si_echo, printlevel;
37extern int    pagelength, colmax;
38extern int    yy_blocklineno;
39extern int    yy_noeof;
40extern char   prompt_char;
41extern const char feNotImplemented[];
42#ifdef HAVE_TCL
43extern BOOLEAN tclmode;
44#endif
45extern BOOLEAN errorreported;
46extern BOOLEAN fe_use_fgets;
47extern BOOLEAN feBatch;
48extern BOOLEAN feProt;
49extern BOOLEAN feWarn;
50extern BOOLEAN feOut;
51
52
53#define PROT_NONE 0
54#define PROT_I    1
55#define PROT_O    2
56#define PROT_IO   3
57
58/* the C-part: */
59#define mflush() fflush(stdout)
60
61#ifdef __cplusplus
62extern "C" {
63#endif
64
65void   Werror(char *fmt, ...);
66void   WerrorS(const char *s);
67void   Print(char* fmt, ...);
68void   PrintLn();
69#ifdef HAVE_TCL
70void   PrintTCLS(const char c, const char * s);
71#else
72#define PrintTCLS(A,B) Print("TCL-ErrS:%s",B)
73#endif
74void   PrintS(char* s);
75
76#ifdef __cplusplus
77}
78/* the C++-part: */
79
80enum   feBufferTypes
81{
82  BT_none  = 0,  // entry level
83  BT_break = 1,  // while, for
84  BT_proc,       // proc
85  BT_example,    // example
86  BT_file,       // <"file"
87  BT_execute,    // execute
88  BT_if,         // if
89  BT_else        // else
90};
91
92enum   feBufferInputs
93{
94  BI_stdin = 1,
95  BI_buffer,
96  BI_file
97};
98
99void    feInitPaths(const char* argv0);
100char*   feGetSearchPath();
101char*   feGetExpandedExecutable();
102char*   feGetBinDir();
103char*   feGetInfoCall(const char* index);
104char*   feGetInfoProgram();
105char*   feGetInfoFile();
106
107FILE *  feFopen(char *path, char *mode, char *where=NULL, int useWerror=FALSE);
108void    fePause(void);
109#ifndef __MWERKS__
110#ifdef HAVE_TCL
111
112inline void PrintTCL(const char c, int l,const char *s)
113{
114  if (s!=NULL) printf("%c:%d:%s",c,l,s);
115  else if(l==0) printf("%c:0:",c);
116  else printf("%c:1:%c",c,'0'+l);
117  fflush(stdout);
118}
119#else
120#define PrintTCL(A,B,C) Print("TCL-Err:%s",C)
121#endif
122#endif
123
124char *  StringAppend(char *fmt, ...);
125char *  StringAppendS(char *s);
126char *  StringSetS(char* s);
127const  char * VoiceName();
128void    VoiceBackTrack();
129void    WarnS(const char *s);
130void    Warn(const char *fmt, ...);
131BOOLEAN contBuffer(feBufferTypes typ);
132char *  eati(char *s, int *i);
133BOOLEAN exitBuffer(feBufferTypes typ);
134BOOLEAN exitVoice();
135void    monitor(char* s,int mode);
136BOOLEAN newFile(char* fname, FILE *f=NULL);
137void    newBuffer(char* s, feBufferTypes t, procinfo *pname = NULL, int start_lineno = 0);
138void *  myynewbuffer();
139void    myyoldbuffer(void * oldb);
140
141class Voice
142{
143  public:
144    Voice  * next;
145    Voice  * prev;
146    char   * filename;    // file name or proc name
147    procinfo * pi;        // proc info
148    void   * oldb;        // internal scanner buffer
149    // for files only:
150    FILE * files;         // file handle
151    // for buffers only:
152    char * buffer;        // buffer pointer
153    long   fptr;          // current position in buffer
154
155    int    start_lineno;  // lineno, to restore in recursion
156    int    curr_lineno;   // current lineno
157    feBufferInputs   sw;  // BI_stdin: read from STDIN
158                          // BI_buffer: buffer
159                          // BI_file: files
160    char   ifsw;          // if-switch:
161            /*1 ifsw==0: no if statement, else is invalid
162            *       ==1: if (0) processed, execute else
163            *       ==2: if (1) processed, else allowed but not executed
164            */
165    feBufferTypes   typ;  // buffer type: see BT_..
166
167  Voice() { memset(this,0,sizeof(*this));}
168  feBufferTypes Typ();
169  void Next();
170} ;
171
172extern Voice  *currentVoice;
173
174Voice * feInitStdin();
175
176/* feread.cc: */
177#ifdef HAVE_FEREAD
178  //void fe_set_input_mode (void);
179  //void fe_temp_set (void);
180  //void fe_temp_reset (void);
181  char * fe_fgets_stdin(char *pr,char *s, int size);
182#else
183  #ifdef HAVE_READLINE
184    void fe_set_input_mode (void);
185    void fe_reset_input_mode (void);
186    char * fe_fgets_stdin_rl(char *pr,char *s, int size);
187    #define fe_fgets_stdin(p,A,B) fe_fgets_stdin_rl(p,A,B)
188  #else
189    #define fe_fgets_stdin(p,A,B) fgets(A,B,stdin)
190  #endif
191#endif
192#endif
193#endif
194
195/* everything in between calls to these procedures is printed into a string
196 * which is returned by SprintEnd()
197 */
198void SPrintStart();
199char* SPrintEnd();
Note: See TracBrowser for help on using the repository browser.