home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / adaptor.zip / adapt.zip / adaptor / src / protocol.c < prev    next >
C/C++ Source or Header  |  1993-07-08  |  6KB  |  252 lines

  1. /**************************************************************************
  2. *                                                                         *
  3. **************************************************************************/
  4.  
  5. #include <stdio.h>
  6. #include "protocol.h" 
  7. #include "Unparse.h"
  8. #include "ShowDefs.h"
  9.  
  10. #undef DEBUG
  11.  
  12. char protocol_name[200];
  13. char unit_name [100];
  14. FILE *protocol;
  15. int error_counter;
  16. int warning_counter;
  17. tTree last_stmt;     /* is always ACF_NODE (label, line, ...) */
  18.  
  19. void open_protocol (name)
  20. char name[];
  21. {
  22.   protocol = fopen (name,"w");
  23.   if (protocol == (FILE *) NULL)
  24.     { printf ("Adaptor failed to open protocol file %s\n", name);
  25.       printf ("Please check permissions\n");
  26.       exit (-1);
  27.     }
  28.   strcpy (protocol_name, name);
  29.   last_stmt = NoTree;
  30.   error_counter = 0;
  31.   warning_counter = 0;
  32. }
  33.  
  34. void close_protocol ()
  35. {
  36.   if (error_counter + warning_counter == 0)
  37.      printf ("Protocol written in File %s\n", protocol_name);
  38.   else if (error_counter == 0)
  39.      printf ("Protocol written in File %s (%d warnings)\n", 
  40.               protocol_name, warning_counter);
  41.   else
  42.      printf ("Protocol written in File %s (%d errors)\n", 
  43.               protocol_name, error_counter);
  44.   fclose (protocol);
  45. }
  46.  
  47. int protocol_errors ()
  48. {
  49.   return (error_counter);
  50. }
  51.  
  52. void set_protocol_unit (t)
  53. tTree t;
  54. { tIdent Name;
  55.   char s[100];
  56.   int i;
  57.  
  58.   last_stmt = NoTree;    /* make sure there is no statement from last unit */
  59.  
  60.   sprintf (unit_name, "");
  61.  
  62.   if (t->Kind == kPROGRAM_DECL)
  63.     { Name = t->PROGRAM_DECL.Name; 
  64.       GetString (Name, s);
  65.       sprintf (unit_name, "PROGRAM %s", s);
  66.     }
  67.   if (t->Kind == kPROC_DECL)
  68.     { Name = t->PROC_DECL.Name; 
  69.       GetString (Name, s);
  70.       sprintf (unit_name, "SUBROUTINE %s", s);
  71.     }
  72.   if (t->Kind == kFUNC_DECL)
  73.     { Name = t->FUNC_DECL.Name; 
  74.       GetString (Name, s);
  75.       sprintf (unit_name, "FUNCTION %s", s);
  76.     }
  77.   if (t->Kind == kMODULE_DECL)
  78.     { Name = t->MODULE_DECL.Name; 
  79.       GetString (Name, s);
  80.       sprintf (unit_name, "MODULE %s", s);
  81.     }
  82.   if (t->Kind == kBLOCK_DATA_DECL)
  83.     { Name = t->BLOCK_DATA_DECL.Name; 
  84.       GetString (Name, s);
  85.       sprintf (unit_name, "BLOCK DATA %s", s);
  86.     }
  87.   fprintf (protocol, "%s\n", unit_name);
  88. #ifdef DEBUG
  89.   printf ("protocol of %s\n", unit_name);
  90. #endif
  91.   for (i=0; i < strlen (unit_name); i++)
  92.      fprintf (protocol, "=");
  93.   fprintf (protocol, "\n\n");
  94. }
  95.  
  96. void set_protocol_stmt (t)
  97. tTree t;
  98. {
  99.   last_stmt = t;
  100. }
  101.  
  102. void print_protocol (s)
  103. char s[];
  104. { fprintf (protocol, "%s\n", s);
  105. #ifdef DEBUG
  106.   printf ("%s\n", s);
  107. #endif
  108. }
  109.  
  110. void tree_protocol (s, t)
  111. char s[];
  112. tTree t;
  113. { fprintf (protocol, "%s",s);
  114.   FileUnparse (protocol, t);
  115.   fprintf (protocol, "\n");
  116. }
  117.  
  118. void obj_protocol (s, o)
  119. char s[];
  120. tObject o;
  121. { fprintf (protocol, "%s",s);
  122.   SemFile = protocol;
  123.   ShowDeclarations (o);
  124.   fprintf (protocol, "\n");
  125. }
  126.  
  127. void simple_error_protocol (s)
  128. char s[];
  129. { error_counter += 1;
  130.   fprintf (protocol, "ERROR : %s\n",s);
  131. #ifdef DEBUG
  132.   printf ("ERROR : %s\n",s);
  133. #endif
  134. }
  135.  
  136. void simple_warning_protocol (s)
  137. char s[];
  138. { warning_counter += 1;
  139.   fprintf (protocol, "WARNING : %s\n",s);
  140. #ifdef DEBUG
  141.   printf ("WARNING : %s\n",s);
  142. #endif
  143. }
  144.  
  145. void tree_error_protocol (s, t)
  146. char s[];
  147. tTree t;
  148. { error_counter += 1;
  149.   fprintf (protocol, "ERROR : %s\n",s);
  150.   FileUnparse (protocol, t);
  151.   fprintf (protocol, "\n");
  152. #ifdef DEBUG
  153.   printf ("ERROR : %s\n",s);
  154.   FileUnparse (stdout, t);
  155.   printf ("\n");
  156. #endif
  157. }
  158.  
  159. void obj_error_protocol (s, o)
  160. char s[];
  161. tObject o;
  162. { error_counter += 1;
  163.   fprintf (protocol, "ERROR : %s\n",s);
  164.   SemFile = protocol;
  165.   ShowDeclarations (o);
  166.   fprintf (protocol, "\n");
  167. #ifdef DEBUG
  168.   printf ("ERROR : %s\n",s);
  169.   SemFile = stdout;
  170.   ShowDeclarations (o);
  171.   printf ("\n");
  172. #endif
  173. }
  174.  
  175. void tree_warning_protocol (s, t)
  176. char s[];
  177. tTree t;
  178. { warning_counter += 1;
  179.   fprintf (protocol, "WARNING : %s",s);
  180.   FileUnparse (protocol, t);
  181.   fprintf (protocol, "\n");
  182. #ifdef DEBUG
  183.   printf ("WARNING : %s",s);
  184.   FileUnparse (stdout, t);
  185.   printf ("\n");
  186. #endif
  187. }
  188.  
  189. void error_protocol (message)
  190. char message[];
  191. { error_counter += 1;
  192.   if (last_stmt != NoTree)
  193.      { fprintf (protocol, "ERROR : %s (Line = %d)\n", 
  194.                            message, last_stmt->ACF_NODE.Line);
  195.        FileUnparse (protocol, last_stmt);
  196.      }
  197.    else
  198.      fprintf (protocol, "ERROR : %s\n", message);
  199. #ifdef DEBUG
  200.   if (last_stmt != NoTree)
  201.      { printf ("ERROR : %s (Line = %d)\n", 
  202.                            message, last_stmt->ACF_NODE.Line);
  203.        FileUnparse (stdout, last_stmt);
  204.      }
  205.    else
  206.      printf ("ERROR : %s\n", message);
  207. #endif
  208. }
  209.  
  210. void stmt_protocol (message)
  211. char message[];
  212. {
  213.   if (last_stmt != NoTree)
  214.      { fprintf (protocol, "%s (Line = %d)\n", 
  215.                            message, last_stmt->ACF_NODE.Line);
  216.        FileUnparse (protocol, last_stmt);
  217.      }
  218.    else
  219.      fprintf (protocol, "O.K. : %s\n", message);
  220. #ifdef DEBUG
  221.   if (last_stmt != NoTree)
  222.      { printf ("%s (Line = %d)\n", 
  223.                            message, last_stmt->ACF_NODE.Line);
  224.        FileUnparse (stdout, last_stmt);
  225.      }
  226.    else
  227.      printf ("O.K. : %s\n", message);
  228. #endif
  229. }
  230.  
  231. void kill_in_protocol ()
  232. { printf ("INTERNAL ERROR, will stop\n");
  233.   close_protocol ();
  234.   exit (-1);
  235. }
  236.  
  237. void failure_protocol (module, proc, t)
  238.  
  239. char module[];
  240. char proc[];
  241. tTree t;
  242.  
  243. { printf ("INTERNAL ERROR: failure in module  = %s\n", module);
  244.   printf ("                procedure/function = %s\n", proc);
  245.   printf ("Tree = "); FileUnparse (stdout, t); printf ("\n");
  246.   WriteTree (stdout, t);
  247.   error_protocol ("stop for internal ERROR");
  248.   close_protocol ();
  249.   exit (-1);
  250. }
  251.  
  252.