Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.16 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "stack.h"
  5. #include "alex.h"
  6.  
  7. static Funkcja *f_head;
  8.  
  9. Wywolanie * store_add( Wywolanie *a_head, int n, char* nazwa ) {
  10.   Wywolanie *tmp = a_head;
  11.  
  12.   if(a_head == NULL) {
  13.     a_head = malloc(sizeof *a_head);
  14.     tmp = a_head;
  15. }
  16.   else{
  17.     while(tmp->next != NULL){
  18.         tmp = tmp->next;
  19. }
  20.     tmp->next = malloc( sizeof( *tmp->next ) );
  21.     tmp=tmp->next;
  22. }
  23.  
  24.   if( tmp == NULL ) fprintf( stderr, "void store_add:20: Nie udalo sie przypisac pamieci!\n" );
  25.  
  26.     tmp->nazwa = strdup( nazwa );
  27.     tmp->n = n;
  28.     tmp->next = NULL;
  29.     return a_head;
  30. }
  31.  
  32. /* zwraca wskaznik struktury przechowujacej informacje o danej funkcji */
  33. Funkcja * store_find_function(char *nazwaf){
  34.   int por; 
  35.   Funkcja *f = f_head;
  36.     while(1){
  37.     if( f == NULL ){
  38.         f = malloc( sizeof * f );
  39.         f->nazwaf = strdup(nazwaf);
  40.         f->next = NULL;
  41.         f->proto = NULL;
  42.         f->def = NULL;
  43.         f->call = NULL;
  44.         f_head = f;
  45.         break;
  46. }
  47.     else{
  48.         por=strcmp(f->nazwaf, nazwaf);
  49.             if(por == 0 ){break;}
  50.             else {
  51.                 if(f->next == NULL){
  52.                     f->next= malloc( sizeof *f );
  53.                     f=f->next;
  54.                     f->nazwaf= strdup(nazwaf);
  55.                     f->next= NULL;
  56.                     f->proto= NULL;
  57.                     f->def= NULL;
  58.                     f->call= NULL;
  59.                     break;
  60. }
  61.                 else {  f=f->next;
  62. }
  63. }
  64. }
  65. }
  66.  
  67.     if(f==NULL)
  68.         fprintf(stderr, "void store_find_structure:49: Nie udalo sie przypisac pamieci!\n");
  69.    
  70. return f;
  71. }
  72.  
  73. /* wypisz liste */
  74. void store_print_list( Wywolanie *tmp, FILE *output ) {
  75.   Wywolanie *last_a;
  76.   int flag = 0;
  77.  
  78.   if(tmp != NULL){
  79.     last_a=tmp;
  80.     fprintf(output, "\t%s: linie:", tmp->nazwa);
  81.     while(tmp!=NULL){
  82.            
  83.         if(strcmp(tmp->nazwa, last_a->nazwa) !=0){
  84.             if(flag ==1){              
  85.                 fprintf(output, "-%d",last_a->n);
  86.                 flag=0;
  87. }
  88.         fprintf(output,"\n\t%s: linie:", tmp->nazwa);
  89.         fprintf(output," %d", tmp->n);
  90. }
  91.         else{                              
  92.             if(tmp->n == last_a->n+1) {
  93.                 flag = 1;
  94. }
  95.             else{
  96.                 if(flag == 1) {             /*Tutaj funkcja wypisuje koniec */
  97.                     fprintf(output, "-%d", last_a->n);
  98.                     flag = 0;
  99. }
  100.                 fprintf( output, " %d", tmp->n );
  101. }
  102. }
  103.         last_a = tmp;
  104.         tmp = tmp->next;
  105. }
  106. }
  107. else{ fprintf(output, "\tbrak");}
  108.  
  109.  
  110. fprintf(output, "\n");
  111. }
  112.  
  113. void store_add_def( char *nazwaf, int n, char* nazwa) {
  114.     Funkcja *f =store_find_function(nazwaf);
  115.     f->def =store_add(f->def, n, nazwa);
  116. }
  117.  
  118. void store_add_proto( char *nazwaf, int n, char* nazwa) {
  119.     Funkcja *f =store_find_function(nazwaf);
  120.     f->proto = store_add(f->proto, n, nazwa);
  121. }
  122.  
  123. void store_add_call( char *nazwaf, int n, char* nazwa) {
  124.     Funkcja *f = store_find_function( nazwaf );
  125.     f->call = store_add( f->call, n, nazwa );
  126. }
  127.  
  128. void store_get_def  ( Funkcja *f ) {
  129.     store_print_list( f->def, stdout );
  130. }
  131. void store_get_proto( Funkcja *f ) {
  132.     store_print_list( f->proto, stdout );
  133. }
  134. void store_get_call ( Funkcja *f ) {
  135.     store_print_list( f->call, stdout );
  136. }
  137.  
  138. void store_p() {
  139.     Funkcja *f = f_head;
  140.     while(f != NULL){
  141.         if( !isKeyword(f->nazwaf)) {
  142.             printf( "%s:\n\tPrototyp:\n", f->nazwaf );
  143.             store_get_proto( f );
  144.             printf( "\tDefinicja:\n" );
  145.             store_get_def( f );
  146.             printf( "\tWywołania:\n" );
  147.             store_get_call( f );
  148.             printf( "\n" );
  149.         }
  150.         f = f->next;
  151.     }
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement