?? output.c
字號:
/********************************************************************* * File: output.c * Description: Functions for printing the data structures or * other general output. * * Author: Joerg Hoffmann / Frank Rittinger * *********************************************************************/ /********************************************************************* * (C) Copyright 1998 Albert Ludwigs University Freiburg * Institute of Computer Science * * All rights reserved. Use of this software is permitted for * non-commercial research purposes, and it may be copied only * for that use. All copies must include this copyright message. * This software is made available AS IS, and neither the authors * nor the Albert Ludwigs University Freiburg make any warranty * about the software or its performance. *********************************************************************/#include "ipp.h"#include "output.h"#include "utilities.h"void print_factlist( FactList *list, char *sepf, char* sept ){ FactList * i_list; TokenList * i_tl; if (NULL != list) { /* Extra handling of first element for pretty printing! */ i_tl = list->item; if (NULL == i_tl || NULL == i_tl->item) { fprintf(stdout, "empty"); } else { fprintf(stdout, "%s", i_tl->item); i_tl = i_tl->next; } while (NULL != i_tl) { if (NULL != i_tl->item) { fprintf(stdout, "%s%s", sept, i_tl->item); } i_tl = i_tl->next; } /* Print the rest. */ for ( i_list = list->next; i_list; i_list = i_list->next ) { fprintf(stdout, "%s", sepf); i_tl = i_list->item; if (NULL == i_tl || NULL == i_tl->item) { fprintf(stdout, "empty"); } else { fprintf(stdout, "%s", i_tl->item); i_tl = i_tl->next; } while (NULL != i_tl) { if (NULL != i_tl->item) { fprintf(stdout, "%s%s", sept, i_tl->item); } i_tl = i_tl->next; } } }}/********************************************************************** * Prints a TokenList to stdout. But does not print tokens * that start with a '#'. * * TokenList * list: The TokenList to print. * char * sep: A separator for the different TokenLists. *********************************************************************/voidprint_tokenlist(TokenList * list, char * sep){ TokenList * i_tl; /* this construction makes the print out nicer, since there is no sep at before the first item and after the last item */ i_tl = list; if (NULL!=i_tl) { /* Only print items that do do not start with '#'. */ if ('#' != *i_tl->item) { fprintf(stdout, "%s", i_tl->item); } i_tl = i_tl->next; } else { fprintf(stdout,"empty"); } while (NULL != i_tl) { /* Only print items that do do not start with '#'. */ if ('#' != *i_tl->item) { fprintf(stdout, "%s%s", sep, i_tl->item); } i_tl = i_tl->next; }}/********************************************************************** * Prints a TokenList to stdout. * * TokenList * list: The TokenList to print. * char * sep: A separator for the different TokenLists. *********************************************************************/voidprint_hidden_tokenlist(TokenList * list, char * sep){ TokenList * i_tl; /* this construction makes the print out nicer, since there is no sep at before the first item and after the last item */ i_tl = list; if (NULL!=i_tl) { /* Only print items that do do not start with '#'. */ fprintf(stdout, "%s", i_tl->item); i_tl = i_tl->next; } else { fprintf(stdout,"empty"); } while (NULL != i_tl) { /* Only print items that do do not start with '#'. */ fprintf(stdout, "%s%s", sep, i_tl->item); i_tl = i_tl->next; }}/********************************************************************** * *********************************************************************/voidprint_indent(int indent){ int i; for (i=0;i<indent;i++) { fprintf(stdout," "); }}/****** TEMPORAL FUNCTION ******/voidspec_error(char * s){ fprintf(stdout, "\nSpecification error at: %s\n", s); exit(EXIT_FAILURE);}/********************************************************************** * at function call the cursor is meant to be intended * at function exit at the beginning of a new line **********************************************************************/voidprint_plnode(PlNode * plnode, int indent){ PlNode * i_son; if (NULL == plnode) { fprintf(stdout, "none\n"); return; } switch (plnode->connective) { case ALL: fprintf(stdout, "ALL %s : %s\n", plnode->atom->item, plnode->atom->next->item); print_indent(indent); fprintf(stdout,"( "); print_plnode(plnode->sons,indent+4); if (NULL!=plnode->sons->next) spec_error("ALL"); print_indent(indent); fprintf(stdout,")\n"); break; case EX: fprintf(stdout, "EX %s : %s\n", plnode->atom->item, plnode->atom->next->item); print_indent(indent); fprintf(stdout,"( "); print_plnode(plnode->sons,indent+4); if (NULL!=plnode->sons->next) spec_error("EX"); print_indent(indent); fprintf(stdout,")\n"); break; case AND: fprintf(stdout,"( "); print_plnode(plnode->sons, indent+4); if (NULL != plnode->sons) { for (i_son = plnode->sons->next; i_son!=NULL; i_son = i_son->next) { print_indent(indent); fprintf(stdout,"AND "); print_plnode(i_son,indent+4); } } print_indent(indent); fprintf(stdout,")\n"); break; case OR: fprintf(stdout,"( "); print_plnode(plnode->sons, indent+4); for (i_son = plnode->sons->next; i_son!=NULL; i_son = i_son->next) { print_indent(indent); fprintf(stdout,"OR "); print_plnode(i_son,indent+4); } print_indent(indent); fprintf(stdout,")\n"); break; case WHEN: fprintf(stdout,"IF "); print_plnode(plnode->sons,indent+5); print_indent(indent); fprintf(stdout,"THEN "); print_plnode(plnode->sons->next,indent+5); if (NULL!=plnode->sons->next->next) spec_error("WHEN"); print_indent(indent); fprintf(stdout,"ENDIF\n"); break; case NOT: if (ATOM==plnode->sons->connective) { fprintf(stdout,"NOT "); print_plnode(plnode->sons,indent+4); } else { fprintf(stdout,"NOT("); print_plnode(plnode->sons,indent+4); print_indent(indent+3); fprintf(stdout,")\n"); } if (NULL!=plnode->sons->next) spec_error("NOT"); break; case TRU: fprintf(stdout,"TRUE\n"); if (NULL!=plnode->sons) spec_error("TRU"); break; case FAL: fprintf(stdout,"FALSE\n"); if (NULL!=plnode->sons) spec_error("FAL"); break; case EMPTY: fprintf(stdout,"EMPTY\n"); if (NULL!=plnode->sons) spec_error("EMPTY"); break; case ATOM: fprintf(stdout,"("); print_hidden_tokenlist(plnode->atom, " "); fprintf(stdout,")\n"); if (NULL!=plnode->sons) spec_error("ATOM"); break; default: fprintf(stdout, "\n***** ERROR ****"); fprintf(stdout, "\nprint_plnode: %d > Wrong Node specifier\n", plnode->connective);/* fprintf(stdout, "\nprint_plnode: %s > Wrong Node specifier\n", gconnectives[plnode->connective]); */ exit(1); ; } } void print_CodeNode( CodeNode *node, int indent ){ CodeNode *i_son; int i, n; Integers *in; if ( !node ) { fprintf(stdout, "none\n"); return; } switch ( node->connective ) { case ALL: printf( "ALL x%d : %s", node->var, gtypes_table[node->var_type].name ); if ( gtypes_table[node->var_type].name == gnew_types_name ) { printf("( "); for ( in = gtypes_table[node->var_type].integers; in; in = in->next ) { printf("%s ", gconstants_table[in->index]); } printf(")"); } printf("\n"); print_indent( indent ); printf( "( " ); print_CodeNode( node->sons, indent+4 ); if ( node->sons->next ) spec_error( "ALL" ); print_indent( indent ); printf(")\n"); break; case EX: printf( "EX x%d : %s", node->var, gtypes_table[node->var_type].name ); if ( gtypes_table[node->var_type].name == gnew_types_name ) { printf("( "); for ( in = gtypes_table[node->var_type].integers; in; in = in->next ) { printf("%s ", gconstants_table[in->index]); } printf(")"); } printf("\n"); print_indent( indent ); printf( "( " ); print_CodeNode( node->sons, indent+4 ); if ( node->sons->next ) spec_error( "ALL" ); print_indent( indent ); printf(")\n"); break; case AND: printf("( "); print_CodeNode( node->sons, indent+4 ); if ( node->sons ) { for (i_son = node->sons->next; i_son!=NULL; i_son = i_son->next) { print_indent(indent); printf("AND "); print_CodeNode( i_son, indent+4 ); } } print_indent(indent); printf(")\n"); break; case OR: printf("( "); print_CodeNode( node->sons, indent+4 ); if ( node->sons ) { for (i_son = node->sons->next; i_son!=NULL; i_son = i_son->next) { print_indent(indent); fprintf(stdout,"OR "); print_CodeNode( i_son, indent+4 ); } } print_indent(indent); printf(")\n"); break; case WHEN: printf("IF "); print_CodeNode( node->sons, indent+5 ); print_indent(indent); printf("THEN "); print_CodeNode( node->sons->next, indent+5 ); if ( node->sons->next && node->sons->next->next ) spec_error("WHEN"); print_indent( indent ); printf("ENDIF\n"); break; case NOT: if ( ATOM == node->sons->connective) { printf("NOT "); print_CodeNode( node->sons, indent+4 ); } else { printf("NOT("); print_CodeNode( node->sons, indent+4 ); print_indent(indent+3); printf(")\n"); } if ( node->sons->next ) spec_error("NOT"); break; case TRU: printf("TRUE\n"); if ( node->sons ) spec_error("TRU"); break; case FAL: printf("FALSE\n"); if ( node->sons ) spec_error("FAL"); break; case EMPTY: printf("EMPTY\n"); if ( node->sons ) spec_error("EMPTY"); break; case ATOM: printf("( %s ", node->predicate == -1 ? "EQ" : gpredicates_table[node->predicate]); n = node->predicate == -1 ? 2 : garity[node->predicate]; for ( i=0; i<n; i++ ) { if ( node->arguments[i] < 0 ) { printf("x%d ", ((-1)*node->arguments[i])-1); } else { printf("%s ", gconstants_table[node->arguments[i]]); } } printf(")\n"); if ( node->sons ) spec_error("ATOM"); break; default: printf("\n***** ERROR ****"); printf("\nprint_CodeNode: %d > Wrong Node specifier\n", node->connective); exit(1); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -