source: git/Singular/febase.cc @ f6b5f0

spielwiese
Last change on this file since f6b5f0 was f6b5f0, checked in by Hans Schönemann <hannes@…>, 27 years ago
* hannes: change Log: and Header: to Id: git-svn-id: file:///usr/local/Singular/svn/trunk@73 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 19.7 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4static char rcsid[] = "$Id: febase.cc,v 1.3 1997-03-24 14:24:36 Singular Exp $";
5/*
6* ABSTRACT: i/o system, handling of 'voices'
7*/
8
9#include <stdlib.h>
10#include <string.h>
11#include <stdio.h>
12#include <limits.h>
13#include <stdarg.h>
14#ifndef macintosh
15#include <unistd.h>
16#endif
17#ifdef NeXT
18#include <sys/file.h>
19#endif
20#include "mod2.h"
21#include "tok.h"
22#include "febase.h"
23#include "mmemory.h"
24#include "subexpr.h"
25#include "ipshell.h"
26
27#define fePutChar(c) fputc((uchar)(c),stdout)
28/*0 implementation */
29
30char fe_promptstr[]
31#ifdef macintosh
32                   =" \n";
33#else
34                   ="  ";
35#endif
36
37class Voices
38{
39  private:
40    void Init()
41    {
42      memset(this,0,sizeof(*this));
43      v_lineno = 1;
44    }
45  public:
46    int    v_lineno;        // lineno, to restore in recursion
47    int    v_oldlineno;     // lineno, to restore at exit
48    int    typ;             // buffer type: see BT_..
49    int    v_echo;          // echo, to restore in recursion
50    int    v_fileVoice;     // to be restored in recursion
51    int    v_inputswitch;   // ??
52    FILE * files;           // file handle
53    long   fptr;            // file | buffer seek
54    char*  filename;        // file name
55    char * buffer;          // buffer pointer
56
57  void Next();
58  Voices() { Init(); }
59  Voices * VFile(char* fname);
60  Voices * Buffer(char* buf, int t);
61  int Exit();
62} ;
63
64
65extern FILE* yyin;
66
67#define INITIAL_PRINT_BUFFER 24*1024
68static int feBufferLength=INITIAL_PRINT_BUFFER;
69static char * feBuffer;
70
71#define START_LEVMAX 32
72int     levmax       = START_LEVMAX;
73Voices *currentVoice = NULL;
74Voices *FileAttribs  =(Voices *)Alloc(START_LEVMAX*sizeof(Voices));
75short  *ifswitch     =(short *)Alloc0(START_LEVMAX*sizeof(short));
76        /*1 ifswitch==0: no if statement, else is invalid
77        *           ==1: if (0) processed, execute else
78        *           ==2: if (1) processed, else allowed but not executed
79        */
80int     si_echo = 0;
81int     printlevel = 0;
82int     fileVoice = 0;
83#ifndef macintosh
84int     pagelength = 24;
85#else
86int     pagelength = -1;
87#endif
88int     colmax = 80;
89int     voice = 0;
90int     inputswitch = 0;
91int     blocklineno = 0;
92char    prompt_char = '>'; /*1 either '>' or '.'*/
93BITSET  verbose = 1
94                  | Sy_bit(V_REDEFINE)
95                  | Sy_bit(V_LOAD_LIB)
96                  | Sy_bit(V_SHOW_USE)
97                  | Sy_bit(V_PROMPT)
98//                  | Sy_bit(V_DEBUG_MEM)
99                  ;
100BOOLEAN errorreported = FALSE;
101BOOLEAN feBatch;
102char *  feErrors=NULL;
103int     feErrorsLen=0;
104
105BOOLEAN feProt = FALSE;
106FILE*   feProtFile;
107BOOLEAN tclmode=FALSE;
108/* TCL-Protocoll (Singular -x): <char type>:<int length>:<string> \n
109*  E:l:s  error - not implemented yet (use N)
110*  W:l:s  warning
111*  N:l:s  stdout
112*  Q:0:   quit
113*  P:0:   prompt >
114*  P:1:   prompt .
115*  R:l:<ring-name> ring change
116* plan:
117*  O:l:<option/no-option> option change (option)
118*  V:l:<option/no-option> option change (verbose)
119*/
120
121/*2
122* fopen, but use 'SingularPath' from environment and '/usr/local/Singular'
123*/
124#ifdef macintosh
125#  define  FS_SEP ','
126#  define  DIR_SEP ':'
127#  define  DIR_SEPP ":"
128#else
129#ifdef MSDOS
130#  define  FS_SEP ';'
131#  define  DIR_SEP '\\'
132#  define  DIR_SEPP "\\"
133#else
134#ifdef atarist
135#  define  FS_SEP ';'
136#  define  DIR_SEP '\\'
137#  define  DIR_SEPP "\\"
138#else  /* unix */
139#  define  FS_SEP ':'
140#  define  DIR_SEP '/'
141#  define  DIR_SEPP "/"
142#endif  /* atarist */
143#endif  /* MSDOS */
144#endif  /* macintosh */
145
146FILE * feFopen(char *path, char *mode, char *where,int useWerror)
147{
148  if (where!=NULL) strcpy(where,path);
149  if ((*mode=='a') ||(*mode=='w') || (path[0]==DIR_SEP)||(path[0]=='.'))
150    return fopen(path,mode);
151  char found = 0;
152  FILE * f=NULL;
153#ifdef MSDOS
154  char *env=getenv("SPATH");
155#else
156  char *env=getenv("SingularPath");
157#endif
158  char *s;
159  if (where==NULL) s=(char *)AllocL(250);
160  else             s=where;
161  if (env!=NULL)
162  {
163    char *p,*q;
164    p = env;
165    while( (q=strchr(p, FS_SEP)) != NULL)
166    {
167      *q = '\0';
168      strcpy(s,p);
169      *q = FS_SEP;
170      strcat(s, DIR_SEPP);
171      strcat(s, path);
172#ifndef macintosh
173      if(!access(s, R_OK)) { found++; break; }
174#else
175      f=fopen(s,mode);
176      if (f!=NULL)  { found++; fclose(f); break; }
177#endif
178      p = q+1;
179    }
180    if(!found)
181    {
182      strcpy(s,p);
183      strcat(s, DIR_SEPP);
184      strcat(s, path);
185    }
186    f=fopen(s,mode);
187    if (f!=NULL)
188    {
189      if (where==NULL) FreeL((ADDRESS)s);
190      return f;
191    }
192  }
193  if (where!=NULL) strcpy(s/*where*/,path);
194  f=fopen(path,mode);
195#ifndef macintosh
196  if (f==NULL)
197  {
198    strcpy(s,"/usr/local/Singular/");
199    strcat(s,path);
200    f=fopen(s,mode);
201  }
202#endif
203  if (where==NULL) FreeL((ADDRESS)s);
204  if ((f==NULL)&&(useWerror))
205    Werror("cannot open `%s`",path);
206  return f;
207}
208
209/*2
210* the name of the current 'voice': the procname (or filename)
211*/
212const char * VoiceName()
213{
214  if (FileAttribs[fileVoice].filename!=NULL)
215    return FileAttribs[fileVoice].filename;
216  return sNoName;
217}
218
219/*2
220* the name of the 'voice' number 'i': the procname (or filename)
221*/
222const char * VoiceName(int i)
223{
224  if (FileAttribs[i].filename!=NULL)
225    return FileAttribs[i].filename;
226  return sNoName;
227}
228
229/*2
230* the type of the current voice:BT_proc, BT_example, BT_file
231*/
232int VoiceType()
233{
234  int i=fileVoice;
235  while ((FileAttribs[i].typ!=BT_proc)
236  &&(FileAttribs[i].typ!=BT_example)
237  &&(FileAttribs[i].typ!=BT_file)
238  &&(i>0))
239    i--;
240  return FileAttribs[i].typ;
241}
242/*2
243* start the file 'fname' (STDIN is stdin) in the current voice (cf.newVoice)
244*/
245Voices * Voices::VFile(char* fname)
246{
247  if (strcmp(fname,"STDIN") == 0)
248  {
249    yyin = stdin;
250    v_inputswitch = 0;
251  }
252  else
253  {
254    yyin = feFopen(fname,"r",NULL,TRUE);
255    v_inputswitch = -1;
256  }
257  files      = yyin;
258  filename   = mstrdup(fname);
259  v_echo     = si_echo;
260  fileVoice  = voice;
261  yylineno   = 1;
262  if (files==NULL)
263  {
264    inputswitch = 0;
265    exitVoice();
266    return NULL;
267  }
268  inputswitch= v_inputswitch;
269  return this;
270}
271
272/*3
273* increment voice counter, allocate new memory
274*/
275static inline void inc_voice()
276{
277  voice++;
278  if (voice >= levmax)
279  {
280    FileAttribs=(Voices *)ReAlloc(FileAttribs,
281                          levmax*sizeof(Voices),
282                          (levmax+16)*sizeof(Voices));
283    ifswitch=(short *)ReAlloc(ifswitch,
284                          levmax*sizeof(short),
285                          (levmax+16)*sizeof(short));
286    memset(&ifswitch[levmax],0,16*sizeof(short));
287    levmax+=16;
288  }
289}
290
291/*2
292* init a new voice similiar to the current
293*/
294void Voices::Next()
295{
296  v_oldlineno = yylineno;
297  v_echo      = si_echo;
298  v_fileVoice = fileVoice;
299  inc_voice();
300
301  currentVoice = &FileAttribs[voice];
302  currentVoice->Init();
303}
304
305/*2
306* start the file 'fname' (STDIN is stdin) as a new voice (cf.VFile)
307*/
308int newVoice(char* s)
309{
310  currentVoice->Next();
311  return (int)currentVoice->VFile((char *)s);
312}
313
314void newBuffer(char* s, int t, char* pname)
315{
316  currentVoice->Next();
317  currentVoice->Buffer(s,t);
318  if (pname) currentVoice->filename = mstrdup(pname);
319  //printf("start buffer %d typ %d\n",voice,t);
320}
321
322Voices * Voices::Buffer(char* buf, int t)
323{
324  inputswitch = v_inputswitch = t;
325  buffer      = buf;
326  typ         = t;
327  //si_echo        = 0;
328  switch (t)
329  {
330    case BT_example:
331    case BT_proc:    v_lineno = yylineno; ::yylineno = 3;     break;
332    case BT_file:    v_lineno = yylineno; ::yylineno = 1;     break;
333    case BT_if:
334    case BT_else:    ::yylineno = v_lineno = blocklineno - 1; break;
335    case BT_break:   ::yylineno = v_lineno = blocklineno - 2; break;
336  }
337  return this;
338}
339
340/*2
341* after leaving a voice:
342* setup everything from the this level
343*/
344int Voices::Exit()
345{
346  if (voice >= 0)
347  {
348    si_echo          = v_echo;
349    fileVoice     = v_fileVoice;
350    yyin          = files;
351    yylineno      = v_oldlineno;
352    inputswitch   = v_inputswitch;
353    return 0;
354  }
355  //Print("Exit:%d\n",voice);
356  return 1;
357}
358
359/*2
360* exit Buffer of type 'typ':
361* returns 1 if buffer type could not be found
362*/
363int exitBuffer(int typ)
364{
365  //printf("exitBuffer: %d\n",typ);
366  if (typ == BT_break)  // valid inside for, while. may skip if, else
367  {
368    /*4 first check for valid buffer type, skip if/else*/
369    for (int i=voice; i>0; i--)
370    {
371      if ((FileAttribs[i].typ == BT_if)
372        ||(FileAttribs[i].typ == BT_else)) continue;
373      if (FileAttribs[i].typ == BT_break /*typ*/)
374      {
375        while ((/*typ*/ BT_break != currentVoice->typ)
376        && (voice > 0))
377        {
378          exitVoice();
379        }
380        return exitVoice();
381      }
382      else return 1;
383    }
384    /*4 break not inside a for/while: return an error*/
385    if (/*typ*/ BT_break != currentVoice->typ) return 1;
386    return exitVoice();
387  }
388
389  if ((typ == BT_proc)
390  || (typ == BT_example))
391  {
392    for (int i=voice; i>0; i--)
393    {
394      if (FileAttribs[i].typ == 0) break;
395      if ((FileAttribs[i].typ == BT_proc)
396      || (FileAttribs[i].typ == BT_example))
397      {
398        while ((BT_proc != currentVoice->typ)
399          && (BT_example != currentVoice->typ)
400        && (voice > 0))
401        {
402          exitVoice();
403        }
404        return exitVoice();
405      }
406    }
407  }
408  /*4 return not inside a proc: return an error*/
409  return 1;
410}
411
412/*2
413* jump to the beginning of a buffer
414*/
415int contBuffer(int typ)
416{
417  if (typ == BT_break)  // valid inside for, while. may skip if, else
418  {
419    // first check for valid buffer type
420    for (int i=voice; i>0; i--)
421    {
422      if ((FileAttribs[i].typ == BT_if)
423        ||(FileAttribs[i].typ == BT_else)) continue;
424      if (FileAttribs[i].typ == BT_break /*typ*/)
425      {
426        while (/*typ*/ BT_break != currentVoice->typ && (voice > i))
427        {
428          exitVoice();
429        }
430        currentVoice->fptr = 0L;
431        yylineno = currentVoice->v_lineno;
432        return 0;
433      }
434      else return 1;
435    }
436  }
437  return 1;
438}
439
440/*2
441* leave a file voice
442*/
443int exitFile()
444{
445  int oldswitch;
446
447  while ((voice > 0) && (inputswitch > 0))
448  {
449    exitVoice();
450  }
451  // now we have left all if-, else-, while-, for-, proc-levels
452  // inside this file;
453  // if the file is the terminal (inputswitch == 0) and
454  // voice >0, so return 1 else return 0
455  // (used for EXIT_CMD in CNTRLC-C-handling)
456  oldswitch = inputswitch;
457  exitVoice();
458  #ifdef SIC
459  return 1;
460  #else
461  if ((oldswitch)||(myynest<0)) return 0;
462  else return 1;
463  #endif
464}
465
466/*2
467* leave a voice: kill local variables
468* setup everything from the previous level (via Exit)
469*/
470int exitVoice()
471{
472  if (voice <= 0)   m2_end(0);
473  //printf("exitVoice %d, typ %d\n",voice,FileAttribs[voice].typ);
474  if (FileAttribs[voice].typ==BT_if)
475  {
476    ifswitch[voice-1]=2;
477  }
478  else
479  {
480    ifswitch[voice-1]=0;
481    //if ((FileAttribs[voice].typ==BT_proc)
482    //||(FileAttribs[voice].typ==BT_example)
483    //||(FileAttribs[voice].typ==0))
484    //{
485    //  killlocals(myynest);
486    //  printf("killlocals %d\n",myynest);
487    //}
488  }
489  if (inputswitch == -1)
490  {
491    fclose(yyin);
492  }
493  else if (inputswitch > 0)
494  {
495    if (FileAttribs[voice].filename!=NULL)
496    {
497      FreeL((ADDRESS)FileAttribs[voice].filename);
498      FileAttribs[voice].filename=NULL;
499    }
500    if (FileAttribs[voice].buffer!=NULL)
501    {
502      FreeL((ADDRESS)FileAttribs[voice].buffer);
503      FileAttribs[voice].buffer=NULL;
504    }
505  }
506  currentVoice = &FileAttribs[--voice];
507  return currentVoice->Exit();
508}
509
510int readbuf(char* buf, int l)
511{
512  char *s;
513  char * t = buf;
514  int i = 0;
515  long fl = currentVoice->fptr;
516  if (fl == -1L)
517  {
518    t[0] = '\0';
519    exitVoice();
520    return 0;
521  }
522
523  s = currentVoice->buffer + fl;
524  while (l > 0)
525  {
526    fl++;
527    i++;
528    l--;
529    *t++ = *s;
530    if (*s == '\n')
531    {
532      *t = '\0';
533      if ((si_echo > voice) || (inputswitch == 0) || (traceit&TRACE_SHOW_LINE)
534      || (traceit&TRACE_SHOW_LINE1))
535      {
536        if (currentVoice->filename==NULL)
537          Print("(none) %3d%c ",yylineno,prompt_char);
538        else if (VoiceType()!=BT_example)
539          Print("%s %3d%c ",currentVoice->filename,yylineno,prompt_char);
540        prompt_char = '.';
541      }
542      if (*(s+1) == '\0')
543      {
544        currentVoice->fptr = -1;
545        FreeL((ADDRESS)(currentVoice->buffer));
546        currentVoice->buffer=NULL;
547        FileAttribs[voice].buffer = NULL;
548        exitVoice();
549      }
550      else
551        currentVoice->fptr = fl;
552      return i;
553    }
554    else if (*s == '\0')
555    {
556      if ((si_echo > voice) || (inputswitch == 0) || (traceit&TRACE_SHOW_LINE)
557      || (traceit&TRACE_SHOW_LINE1))
558      {
559        if (currentVoice->filename==NULL)
560          Print("(none) %3d%c ",yylineno,prompt_char);
561        else
562          Print("%s %3d%c ",currentVoice->filename,yylineno,prompt_char);
563        prompt_char = '.';
564      }
565      currentVoice->fptr = -1;
566      FreeL((ADDRESS)(currentVoice->buffer));
567      currentVoice->buffer = NULL;
568      exitVoice();
569      return i-1;
570    }
571    s++;
572  }
573  currentVoice->fptr = fl;
574  return i;
575}
576
577/*2
578* init all data structures
579*/
580void I_FEbase(void)
581{
582  FileAttribs[0].files       = yyin = stdin;
583  FileAttribs[0].filename    = mstrdup("STDIN");
584  yylineno = 1;
585  currentVoice = &FileAttribs[0];
586  feBuffer = (char *)Alloc(INITIAL_PRINT_BUFFER);
587}
588
589char * feBufferStart;
590  /* only used in StringSet(S)/StringAppend(S)*/
591char * StringAppend(char *fmt, ...)
592{
593  va_list ap;
594  char *s = feBufferStart; /*feBuffer + strlen(feBuffer);*/
595  int more;
596  va_start(ap, fmt);
597  if ((more=feBufferStart-feBuffer+strlen(fmt)+100)>feBufferLength)
598  {
599    more = ((more + (4*1024-1))/(4*1024))*(4*1024);
600    int l=s-feBuffer;
601    feBuffer=(char *)ReAlloc((ADDRESS)feBuffer,feBufferLength,
602                                                     more);
603    feBufferLength=more;
604    s=feBuffer+l;
605#ifndef BSD_SPRINTF
606    feBufferStart=s;
607#endif
608  }
609#ifdef BSD_SPRINTF
610  vsprintf(s, fmt, ap);
611  while (*s!='\0') s++;
612  feBufferStart =s;
613#else
614  feBufferStart += vsprintf(s, fmt, ap);
615#endif
616  va_end(ap);
617  return feBuffer;
618}
619
620char * StringAppendS(char *st)
621{
622  /* feBufferStart is feBuffer + strlen(feBuffer);*/
623  int more,l;
624  int ll=feBufferStart-feBuffer;
625  if ((more=ll+(l=strlen(st)))>feBufferLength)
626  {
627    more = ((more + (4*1024-1))/(4*1024))*(4*1024);
628    feBuffer=(char *)ReAlloc((ADDRESS)feBuffer,feBufferLength,
629                                                     more);
630    feBufferLength=more;
631    feBufferStart=feBuffer+ll;
632  }
633  strcat(feBufferStart, st);
634  feBufferStart +=l;
635  return feBuffer;
636}
637
638char * StringSet(char *fmt, ...)
639{
640  va_list ap;
641  char *s = feBuffer;
642  va_start(ap, fmt);
643#ifdef BSD_SPRINTF
644  vsprintf(s, fmt, ap);
645  while (*s!='\0') s++;
646  feBufferStart = s;
647#else
648  feBufferStart = feBuffer + vsprintf(s, fmt, ap);
649#endif
650  va_end(ap);
651  return feBuffer;
652}
653
654char * StringSetS(char *st)
655{
656  int more,l;
657  if ((l=strlen(st))>feBufferLength)
658  {
659    more = ((l + (4*1024-1))/(4*1024))*(4*1024);
660    feBuffer=(char *)ReAlloc((ADDRESS)feBuffer,feBufferLength,
661                                                     more);
662    feBufferLength=more;
663  }
664  strcpy(feBuffer,st);
665  feBufferStart=feBuffer+l;
666  return feBuffer;
667}
668
669void PrintTCLS(char c, char *s)
670{
671#ifndef macintosh
672  int l=strlen(s);
673  if (l>0) PrintTCL(c,l,s);
674#endif
675}
676
677void WerrorS(char *s)
678{
679#ifdef HAVE_MPSR
680  if (feBatch)
681  {
682    if (feErrors==NULL)
683    {
684      feErrors=(char *)Alloc(256);
685      feErrorsLen=256;
686      strcpy(feErrors,s);
687    }
688    else
689    {
690      if (((int)(strlen(s)+strlen(feErrors)))>=feErrorsLen)
691      {
692        feErrors=(char *)ReAlloc(feErrors,feErrorsLen,feErrorsLen+256);
693        feErrorsLen+=256;
694      }
695      strcat(feErrors,s);
696    }
697    strcat(feErrors,"\n");
698  }
699  else
700#endif
701  {
702#ifdef HAVE_TCL
703    if (tclmode)
704    {
705      //PrintTCLS('E',s);
706      //PrintTCLS('E',"\n");
707      PrintTCLS('N',s);
708      PrintTCLS('N',"\n");
709    }
710    else
711#endif
712    {
713      fwrite("   ? ",1,5,stderr);
714      fwrite(s,1,strlen(s),stderr);
715      fwrite("\n",1,1,stderr);
716      fflush(stderr);
717      if (feProt&PROT_O)
718      {
719        fwrite("   ? ",1,5,feProtFile);
720        fwrite(s,1,strlen(s),feProtFile);
721        fwrite("\n",1,1,feProtFile);
722      }
723    }
724  }
725  errorreported = TRUE;
726}
727
728extern "C" {
729void Werror(char *fmt, ...)
730{
731  va_list ap;
732  va_start(ap, fmt);
733  char *s=(char *)Alloc(256);
734  vsprintf(s, fmt, ap);
735  WerrorS(s);
736  Free(s,256);
737  va_end(ap);
738}
739}
740
741void WarnS(char *s)
742{
743#ifdef HAVE_TCL
744  if (tclmode)
745  {
746    PrintTCLS('W',s);
747  }
748  else
749#endif
750  {
751    fwrite("// ** ",1,6,stdout);
752    fwrite(s,1,strlen(s),stdout);
753    fwrite("\n",1,1,stdout);
754    fflush(stdout);
755    if (feProt&PROT_O)
756    {
757      fwrite("// ** ",1,6,feProtFile);
758      fwrite(s,1,strlen(s),feProtFile);
759      fwrite("\n",1,1,feProtFile);
760    }
761  }
762}
763
764void Warn(char *fmt, ...)
765{
766  va_list ap;
767  va_start(ap, fmt);
768  char *s=(char *)Alloc(256);
769  vsprintf(s, fmt, ap);
770  WarnS(s);
771  Free(s,256);
772  va_end(ap);
773}
774
775#ifdef macintosh
776static  int lines = 0;
777static  int cols = 0;
778void mwrite(uchar c)
779{
780  if (c == '\n')
781  {
782    cols = 0;
783    if (lines == pagelength)
784    {
785      lines = 0;
786      fePause();
787    }
788    else
789    {
790      lines++;
791      fePutChar(c);
792    }
793  }
794  else
795  {
796    fePutChar(c);
797    cols++;
798    if (cols == colmax)
799    {
800//      cols = 0;   //will be done by mwrite('\n');
801      mwrite('\n');
802    }
803  }
804}
805#endif
806
807void PrintS(char *s)
808{
809#ifdef macintosh
810  char c;
811  while ('\0' != (c = *s++))
812  {
813    mwrite(c);
814  }
815#else
816#ifdef HAVE_TCL
817  if (tclmode)
818  {
819    PrintTCLS('N',s);
820  }
821  else
822#endif
823  {
824    fwrite(s,1,strlen(s),stdout);
825    fflush(stdout);
826    if (feProt&PROT_O)
827    {
828      fwrite(s,1,strlen(s),feProtFile);
829    }
830  }
831#endif
832}
833
834void Print(char *fmt, ...)
835{
836  va_list ap;
837  va_start(ap, fmt);
838#ifdef HAVE_TCL
839  if(tclmode)
840#endif
841#if (defined(HAVE_TCL) || defined(macintosh))
842  {
843    char *s=(char *)Alloc(strlen(fmt)+256);
844    vsprintf(s,fmt, ap);
845#ifdef HAVE_TCL
846    PrintTCLS('N',s);
847#endif
848#ifdef macintosh
849  char c;
850  while ('\0' != (c = *s++))
851  {
852    mwrite(c);
853  }
854  if (feProt&PROT_O)
855  {
856    vfprintf(feProrFile,fmt,ap);
857  }
858#endif
859  }
860#endif
861#if !defined(macintosh) || defined(HAVE_TCL)
862#ifdef HAVE_TCL
863  else
864#endif
865  {
866    vfprintf(stdout, fmt, ap);
867    fflush(stdout);
868    if (feProt&PROT_O)
869    {
870      vfprintf(feProtFile,fmt,ap);
871    }
872  }
873#endif
874  va_end(ap);
875}
876
877void PrintLn()
878{
879  PrintS("\n");
880}
881
882void fePause()
883{
884  uchar c;
885  mflush();
886#ifndef macintosh
887  fputs("pause>",stderr);
888#else
889  fputs("pause>\n",stderr);
890#endif
891  c = fgetc(stdin);
892  if (((c == '\003') || (c == 'C')) || (c == 'c'))
893  {
894    m2_end(1);
895  }
896}
897
898/*2
899* print input lines (si_echo or TRACE), set prompt_char
900*/
901void showInput(void)
902{
903  if ((inputswitch <= 0) || (traceit&TRACE_SHOW_LINE)
904  || (traceit&TRACE_SHOW_LINE1))
905  {
906    if ((si_echo > voice) || (inputswitch == 0) || (traceit&TRACE_SHOW_LINE)
907    || (traceit&TRACE_SHOW_LINE1))
908    {
909#ifdef HAVE_TCL
910      if (tclmode)
911      {
912         PrintTCL('P',(prompt_char=='>')? 0 : 1,NULL);
913      }
914      else
915#endif
916      if (BVERBOSE(V_PROMPT))
917      {
918        if (inputswitch == 0)
919        {
920          fe_promptstr[0]=prompt_char;
921#ifndef HAVE_READLINE
922          PrintS(fe_promptstr);
923#endif
924        }
925        else
926        {
927          if (currentVoice->filename==NULL)
928            Print("(none) %3d%c ",yylineno,prompt_char);
929          else
930            Print("%s %3d%c ",currentVoice->filename,yylineno,prompt_char);
931        }
932        prompt_char = '.';
933        mflush();
934      }
935#ifdef macintosh
936      cols = 0;
937#endif
938    }
939  }
940}
941
942void monitor(char* s, int mode)
943{
944  if (feProt)
945  {
946    fclose(feProtFile);
947  }
948  if ((s!=NULL) && (*s!='\0'))
949  {
950    feProtFile = fopen(s,"w");
951    if (feProtFile==NULL)
952    {
953      Werror("cannot open %s",s);
954    }
955    else
956      feProt = (BOOLEAN)mode;
957  }
958}
959
960
961char* eati(char *s, int *i)
962{
963  int l=0;
964
965  if    (*s >= '0' && *s <= '9')
966  {
967    *i = 0;
968    while (*s >= '0' && *s <= '9')
969    {
970      *i *= 10;
971      *i += *s++ - '0';
972      l++;
973      if ((l>MAX_INT_LEN)||((*i) <0))
974      {
975        s-=l;
976        Werror("`%s` greater than %d(max. integer representation)",
977                s,INT_MAX);
978        return s;
979      }
980    }
981  }
982  else *i = 1;
983  return s;
984}
985
Note: See TracBrowser for help on using the repository browser.