Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "stack.h"
- #include "alex.h"
- static Funkcja *f_head;
- Wywolanie * store_add( Wywolanie *a_head, int n, char* nazwa ) {
- Wywolanie *tmp = a_head;
- if(a_head == NULL) {
- a_head = malloc(sizeof *a_head);
- tmp = a_head;
- }
- else{
- while(tmp->next != NULL){
- tmp = tmp->next;
- }
- tmp->next = malloc( sizeof( *tmp->next ) );
- tmp=tmp->next;
- }
- if( tmp == NULL ) fprintf( stderr, "void store_add:20: Nie udalo sie przypisac pamieci!\n" );
- tmp->nazwa = strdup( nazwa );
- tmp->n = n;
- tmp->next = NULL;
- return a_head;
- }
- /* zwraca wskaznik struktury przechowujacej informacje o danej funkcji */
- Funkcja * store_find_function(char *nazwaf){
- int por;
- Funkcja *f = f_head;
- while(1){
- if( f == NULL ){
- f = malloc( sizeof * f );
- f->nazwaf = strdup(nazwaf);
- f->next = NULL;
- f->proto = NULL;
- f->def = NULL;
- f->call = NULL;
- f_head = f;
- break;
- }
- else{
- por=strcmp(f->nazwaf, nazwaf);
- if(por == 0 ){break;}
- else {
- if(f->next == NULL){
- f->next= malloc( sizeof *f );
- f=f->next;
- f->nazwaf= strdup(nazwaf);
- f->next= NULL;
- f->proto= NULL;
- f->def= NULL;
- f->call= NULL;
- break;
- }
- else { f=f->next;
- }
- }
- }
- }
- if(f==NULL)
- fprintf(stderr, "void store_find_structure:49: Nie udalo sie przypisac pamieci!\n");
- return f;
- }
- /* wypisz liste */
- void store_print_list( Wywolanie *tmp, FILE *output ) {
- Wywolanie *last_a;
- int flag = 0;
- if(tmp != NULL){
- last_a=tmp;
- fprintf(output, "\t%s: linie:", tmp->nazwa);
- while(tmp!=NULL){
- if(strcmp(tmp->nazwa, last_a->nazwa) !=0){
- if(flag ==1){
- fprintf(output, "-%d",last_a->n);
- flag=0;
- }
- fprintf(output,"\n\t%s: linie:", tmp->nazwa);
- fprintf(output," %d", tmp->n);
- }
- else{
- if(tmp->n == last_a->n+1) {
- flag = 1;
- }
- else{
- if(flag == 1) { /*Tutaj funkcja wypisuje koniec */
- fprintf(output, "-%d", last_a->n);
- flag = 0;
- }
- fprintf( output, " %d", tmp->n );
- }
- }
- last_a = tmp;
- tmp = tmp->next;
- }
- }
- else{ fprintf(output, "\tbrak");}
- fprintf(output, "\n");
- }
- void store_add_def( char *nazwaf, int n, char* nazwa) {
- Funkcja *f =store_find_function(nazwaf);
- f->def =store_add(f->def, n, nazwa);
- }
- void store_add_proto( char *nazwaf, int n, char* nazwa) {
- Funkcja *f =store_find_function(nazwaf);
- f->proto = store_add(f->proto, n, nazwa);
- }
- void store_add_call( char *nazwaf, int n, char* nazwa) {
- Funkcja *f = store_find_function( nazwaf );
- f->call = store_add( f->call, n, nazwa );
- }
- void store_get_def ( Funkcja *f ) {
- store_print_list( f->def, stdout );
- }
- void store_get_proto( Funkcja *f ) {
- store_print_list( f->proto, stdout );
- }
- void store_get_call ( Funkcja *f ) {
- store_print_list( f->call, stdout );
- }
- void store_p() {
- Funkcja *f = f_head;
- while(f != NULL){
- if( !isKeyword(f->nazwaf)) {
- printf( "%s:\n\tPrototyp:\n", f->nazwaf );
- store_get_proto( f );
- printf( "\tDefinicja:\n" );
- store_get_def( f );
- printf( "\tWywołania:\n" );
- store_get_call( f );
- printf( "\n" );
- }
- f = f->next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement