/[ascend]/trunk/base/generic/utilities/ascPrint.c
ViewVC logotype

Diff of /trunk/base/generic/utilities/ascPrint.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 48 by ben.allan, Sat Mar 5 01:53:39 2005 UTC revision 49 by ben.allan, Tue Apr 12 23:36:01 2005 UTC
# Line 44  static struct Asc_PrintVTable *g_Asc_pri Line 44  static struct Asc_PrintVTable *g_Asc_pri
44    
45  int Asc_PrintPushVTable(struct Asc_PrintVTable *vtable)  int Asc_PrintPushVTable(struct Asc_PrintVTable *vtable)
46  {  {
47      if (    vtable->name == NULL ||      if (    vtable == NULL ||
48            vtable->name == NULL ||
49          vtable->print == NULL ||          vtable->print == NULL ||
50          vtable->fflush == NULL          vtable->fflush == NULL
51         ) {         ) {
# Line 54  int Asc_PrintPushVTable(struct Asc_Print Line 55  int Asc_PrintPushVTable(struct Asc_Print
55      assert(vtable->next == NULL);      assert(vtable->next == NULL);
56      vtable->next = g_Asc_printVtables;      vtable->next = g_Asc_printVtables;
57      g_Asc_printVtables = vtable;      g_Asc_printVtables = vtable;
58        return 0;
59  }  }
60    
61  extern struct Asc_PrintVTable * Asc_PrintRemoveVTable(CONST char *name)  struct Asc_PrintVTable * Asc_PrintRemoveVTable(CONST char *name)
62  {  {
63      struct Asc_PrintVTable * prev;      struct Asc_PrintVTable * prev;
64      struct Asc_PrintVTable * vt;      struct Asc_PrintVTable * vt;
# Line 66  extern struct Asc_PrintVTable * Asc_Prin Line 68  extern struct Asc_PrintVTable * Asc_Prin
68          return NULL;          return NULL;
69      }      }
70      /* LIFO is easy */      /* LIFO is easy */
71        vt = g_Asc_printVtables;
72      if ( strcmp(vt->name,name) == 0 ) {      if ( strcmp(vt->name,name) == 0 ) {
73          struct Asc_PrintVTable * vt = g_Asc_printVtables;          g_Asc_printVtables = vt->next;
         g_Asc_printVtables = g_Asc_printVtables->next;  
74          return vt;          return vt;
75      }      }
76      /* middle chain is worse */      /* middle chain is worse */
# Line 97  extern struct Asc_PrintVTable * Asc_Prin Line 99  extern struct Asc_PrintVTable * Asc_Prin
99   *  This function just initializes the variable_number_args into a   *  This function just initializes the variable_number_args into a
100   *  va_list, and then calls AscPrint to actually do the work.   *  va_list, and then calls AscPrint to actually do the work.
101   */   */
 extern  
102  int Asc_Printf(CONST char *format, ...)  int Asc_Printf(CONST char *format, ...)
103  {  {
104    va_list args;    /* the variable number of arguments */    va_list args;    /* the variable number of arguments */
105    int result;      /* the result of the call to AscPrint; our return value */    int result = 0;  /* the result of the call to AscPrint; our return value */
106    
107    struct Asc_PrintVTable * vt = g_Asc_printVtables;    struct Asc_PrintVTable * vt = g_Asc_printVtables;
108    while (vt != NULL) {    while (vt != NULL) {
109        /* create the va_list */        /* create the va_list */
110        va_start( args, format );        va_start( args, format );
111        result = vt->print( stdout, format, args );        result = vt->print( stdout, format, args );
112        /* cleanup and return */        /* cleanup */
113        va_end( args );        va_end( args );
114        vt = vt->next;        vt = vt->next;
115    }    }
116      /* only the result of the last printer makes it out */
117    return result;    return result;
118  }  }
119    
# Line 128  int Asc_Printf(CONST char *format, ...) Line 130  int Asc_Printf(CONST char *format, ...)
130   *  This function just initializes the variable_number_args into a   *  This function just initializes the variable_number_args into a
131   *  va_list, and then calls AscPrint to actually do the work.   *  va_list, and then calls AscPrint to actually do the work.
132   */   */
 extern  
133  int Asc_FPrintf(FILE *fp, CONST char *format, ...)  int Asc_FPrintf(FILE *fp, CONST char *format, ...)
134  {  {
135    va_list args;    /* the variable number of arguments */    va_list args;    /* the variable number of arguments */
136    int result;      /* the result of the call to AscPrint; our return value */    int result=0;    /* the result of the call to AscPrint; our return value */
137    
138    struct Asc_PrintVTable * vt = g_Asc_printVtables;    struct Asc_PrintVTable * vt = g_Asc_printVtables;
139    while (vt != NULL) {    while (vt != NULL) {
# Line 143  int Asc_FPrintf(FILE *fp, CONST char *fo Line 144  int Asc_FPrintf(FILE *fp, CONST char *fo
144        va_end( args );        va_end( args );
145        vt = vt->next;        vt = vt->next;
146    }    }
147      /* only the result of the last printer makes it out */
148    return result;    return result;
149  }  }
150    
# Line 156  int Asc_FPrintf(FILE *fp, CONST char *fo Line 158  int Asc_FPrintf(FILE *fp, CONST char *fo
158   *   *
159   *  This is needed for consistency with Asc_FPrintf() and Asc_Printf().   *  This is needed for consistency with Asc_FPrintf() and Asc_Printf().
160   */   */
 extern  
161  int Asc_FFlush( FILE *fileptr )  int Asc_FFlush( FILE *fileptr )
162  {  {
163    int result;    int result = 0;
164    struct Asc_PrintVTable * vt = g_Asc_printVtables;    struct Asc_PrintVTable * vt = g_Asc_printVtables;
165    while (vt != NULL) {    while (vt != NULL) {
166        result = vt->fflush(fileptr);        result = vt->fflush(fileptr);
167        vt = vt->next;        vt = vt->next;
168    }    }
169      /* only the result of the last printer makes it out */
170    return result;    return result;
171  }  }
172    
# Line 179  int Asc_FFlush( FILE *fileptr ) Line 181  int Asc_FFlush( FILE *fileptr )
181   *   *
182   *  This is needed for consistency with Asc_FPrintf() and Asc_Printf().   *  This is needed for consistency with Asc_FPrintf() and Asc_Printf().
183   */   */
 extern  
184  int Asc_FPutc( int c, FILE *fileptr )  int Asc_FPutc( int c, FILE *fileptr )
185  {  {
186    /*    /*
# Line 203  int Asc_FPutc( int c, FILE *fileptr ) Line 204  int Asc_FPutc( int c, FILE *fileptr )
204   *   *
205   *  This is needed for consistency with Asc_FPrintf() and Asc_Printf().   *  This is needed for consistency with Asc_FPrintf() and Asc_Printf().
206   */   */
 extern  
207  int Asc_Putchar( int c )  int Asc_Putchar( int c )
208  {  {
209    return Asc_Printf( "%c", c );    return Asc_Printf( "%c", c );

Legend:
Removed from v.48  
changed lines
  Added in v.49

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22