G:/ScriptBasic/source/commands/print.c

Go to the documentation of this file.
00001 /*print.c
00002 
00003 --GNU LGPL
00004 This library is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU Lesser General Public
00006 License as published by the Free Software Foundation; either
00007 version 2.1 of the License, or (at your option) any later version.
00008 
00009 This library is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 Lesser General Public License for more details.
00013 
00014 You should have received a copy of the GNU Lesser General Public
00015 License along with this library; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018 */
00019 
00020 #include <stdlib.h>
00021 #include <stdio.h>
00022 #include <string.h>
00023 #include "../command.h"
00024 
00025 /*POD
00026 =H PRINT command
00027 
00028 This file implements the two print commands that print to the standard output.
00029 The print commands that print to a file are implemented in T<file.c>
00030 
00031 The difference between the standard output printing and file printing commands
00032 are that the file printing commands use th T<#> character to specify the file
00033 number.
00034 
00035 CUT*/
00036 
00037 /*POD
00038 =section printNL
00039 =H Print a new line character
00040 =verbatim
00041   print
00042 =noverbatim
00043 
00044 This command is a print command without any argument. This command prints a new line
00045 character to the standard output. Note however that the R<print> command that has arguments
00046 does not print new line character aftre the results of the expressions are printed to the standard
00047 output. Therefore the following two statements are identical, altough the second generates somewhat longer code:
00048 
00049 =verbatim
00050 print
00051 print "\n"
00052 =noverbatim
00053 
00054 CUT*/
00055 COMMAND(PRINTNL)
00056 #if NOTIMP_PRINTNL
00057 NOTIMPLEMENTED;
00058 #else
00059 
00060   void (*fpExtOut)(char, void *);
00061 
00062   fpExtOut = pEo->fpStdouFunction;
00063 
00064   if( fpExtOut )
00065     fpExtOut('\n',pEo->pEmbedder);
00066   else
00067     printf("\n");
00068 
00069 #endif
00070 END
00071 
00072 /*POD
00073 =section print
00074 =H Print expression values to standard output
00075 =verbatim
00076 print expression_list
00077 =noverbatim
00078 
00079 This command prints the values of the expressions to the standard output. The expressions
00080 are evaluated and the value is formmatted according to their actual type.
00081 
00082 Long values are printed using the format T<%ld>.
00083 
00084 Double values are printed using the format T<%lf>.
00085 
00086 String values are printed sending each character to the standard output.
00087 
00088 CUT*/
00089 COMMAND(PRINT)
00090 #if NOTIMP_PRINT
00091 NOTIMPLEMENTED;
00092 #else
00093   NODE nItem;
00094   VARIABLE ItemResult;
00095   char *s;
00096   unsigned long slen;
00097   void (*fpExtOut)(char, void *);
00098   char buffer[40];
00099 
00100   fpExtOut = pEo->fpStdouFunction;
00101   nItem = PARAMETERNODE;
00102   while( nItem ){
00103     ItemResult = _EVALUATEEXPRESSION_A(CAR(nItem));
00104     ASSERTOKE;
00105 
00106     if( memory_IsUndef(ItemResult) )
00107       strcpy(buffer,"undef");
00108     else
00109     switch( TYPE(ItemResult) ){
00110       case VTYPE_LONG:
00111         sprintf(buffer,"%ld",LONGVALUE(ItemResult));
00112         break;
00113       case VTYPE_DOUBLE:
00114         sprintf(buffer,"%le",DOUBLEVALUE(ItemResult));
00115         break;
00116       case VTYPE_STRING:
00117         s = STRINGVALUE(ItemResult);
00118         slen = STRLEN(ItemResult);
00119         while( slen -- )
00120           if( fpExtOut )
00121             fpExtOut(*s++,pEo->pEmbedder);
00122           else
00123             putc(((int)*s++),stdout);
00124           *buffer = (char)0;/* do not print anything afterwards */
00125         break;
00126       case VTYPE_ARRAY:
00127         sprintf(buffer,"ARRAY@#%08X",LONGVALUE(ItemResult));
00128         break;
00129       }
00130 
00131     s = buffer;
00132     while( *s )
00133       if( fpExtOut )
00134         fpExtOut(*s++,pEo->pEmbedder);
00135       else
00136         putc(((int)*s++),stdout);
00137 
00138     nItem = CDR(nItem);
00139     }
00140 
00141 
00142 #endif
00143 END
00144 

Generated on Sun Mar 12 23:56:27 2006 for ScriptBasic by  doxygen 1.4.6-NO