summaryrefslogtreecommitdiff
path: root/biblio/bibtex/utils/xbibfile/listyears.c
blob: 2b1f79a060a9c3a6b95b76c32e7326f813d57d6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/* This file is a part of XBibFile - a system for handling BibTeX references
 *
 * Author:   Ross Maloney
 * Date:     January 2002
 *
 */

#include  <stdio.h>
#include  <string.h>
#include  <gtk/gtk.h>


GtkWidget  *searchlabel, *searchword;
GtkWidget  *text, *textblock, *scrollblock;
GtkWidget  *summary;
GtkTextBuffer  *textpad;
GtkTextIter  iter;

char  holder[200], temp[200], report[30], seek[100];
char  type[20], tag[30], title[100];

void  allyears(GtkWidget *widget)
{
  GtkTooltips  *tooltips;
  GtkWidget  *window, *panel, *description, *selector, *controls;
  GtkWidget  *key0, *key1;

  extern  void  close_window(GtkWidget *);    /* defined in file cleanup.c */
  void  put_all_years();

  tooltips = gtk_tooltips_new();

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title(GTK_WINDOW(window), "XBibFile inspect");
  gtk_window_position(GTK_WINDOW(window), GTK_WIN_POS_MOUSE);
  gtk_window_set_default_size(GTK_WINDOW(window), 500, 470);
  panel = gtk_vbox_new(FALSE, 0);
  gtk_container_add(GTK_CONTAINER(window), panel);
  description = gtk_label_new("All publication date fields in database");
  gtk_box_pack_start(GTK_BOX(panel), description, FALSE, TRUE, 10);

                          /* create the text display part of the window */
  textblock = gtk_scrolled_window_new(NULL, NULL);
  textpad = gtk_text_buffer_new(NULL);
  text = gtk_text_view_new_with_buffer(textpad);
  gtk_container_add(GTK_CONTAINER(textblock), text);
  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(textblock),
                                 GTK_POLICY_AUTOMATIC,
				 GTK_POLICY_AUTOMATIC);
  gtk_box_pack_start_defaults(GTK_BOX(panel), textblock); 

                           /* put the window control buttons in place */
  controls = gtk_hbox_new(FALSE, 0);
  key0 = gtk_button_new_with_label("CANCEL");
  gtk_widget_set_usize(GTK_WIDGET(key0), 90, -1);
  g_signal_connect(GTK_OBJECT(key0), "clicked",
                   G_CALLBACK(close_window), NULL);
  gtk_tooltips_set_tip(tooltips, key0,
                       "Finish this reference probe", NULL);
  gtk_box_pack_end(GTK_BOX(controls), key0, FALSE, FALSE, 10);
                           /* and put the summary line in place */
  summary = gtk_entry_new();
  gtk_editable_set_editable(GTK_EDITABLE(summary), FALSE);
  gtk_widget_set_usize(GTK_WIDGET(summary), 150, 20);
  gtk_box_pack_start(GTK_BOX(controls), summary, FALSE, FALSE, 10);
  gtk_box_pack_end(GTK_BOX(panel), controls, FALSE, TRUE, 20);

                          /* now put the 'style' for the text output */
  gtk_text_buffer_create_tag(textpad, "blackface",
                             "foreground", "black", NULL);
  gtk_text_buffer_create_tag(textpad, "emphasis",
                             "foreground", "red", NULL);
  gtk_text_buffer_create_tag(textpad, "target",
                             "foreground", "green", NULL);
  gtk_text_buffer_create_tag(textpad, "point",
                             "size", 11 * PANGO_SCALE, NULL);
  gtk_text_buffer_create_tag(textpad, "font",
                             "style", PANGO_STYLE_NORMAL, NULL);

  put_all_years(widget);

                          /* put the composite window on the screen */
  gtk_widget_show_all(window);
}



/* This procedure performs the searching of the BibTeX database and returns
 * its results to the text window created in the procedure  allyears()  above
 */

void  put_all_years(GtkWidget *widget)
{
  int  i, count, length;
  char  *start, *end;

  extern  void  error();                      /* defined in file error.c */
  extern  FILE  *refFile;                     /* defined in xbibfile.c */


  i = 0;
  count = 0;
  rewind(refFile);
  gtk_text_buffer_get_iter_at_offset(textpad, &iter, 0);
  while ( ( holder[i] = getc(refFile) ) != EOF )  {
    if ( holder[i] == '\n' )  {
      holder[i+1] = '\0';
      i = 0;
      if ( holder[0] == '@' )  {
        if ( strstr( holder, "ARTICLE") ) 
	  strcpy(temp, "Article   ");
        if ( strstr( holder, "BOOK") ) 
	  strcpy(temp, "Book   ");
        if ( strstr( holder, "BOOKLET") ) 
	  strcpy(temp, "Booklet   ");
        if ( strstr( holder, "CONFERENCE") ) 
	  strcpy(temp, "Conference  ");
        if ( strstr( holder, "INBOOK") ) 
	  strcpy(temp, "inBook   ");
        if ( strstr( holder, "INCOLLECTION") ) 
	  strcpy(temp, "Incollection   ");
        if ( strstr( holder, "INPROCEEDINGS") ) 
	  strcpy(temp, "inProceedings   ");
        if ( strstr( holder, "MANUAL") ) 
	  strcpy(temp, "Manual   ");
        if ( strstr( holder, "MASTERSTHESIS") ) 
	  strcpy(temp, "Masters   ");
        if ( strstr( holder, "MISC") ) 
	  strcpy(temp, "Misc   ");
        if ( strstr( holder, "PHDTHESIS") ) 
	  strcpy(temp, "PhD Thesis   ");
        if ( strstr( holder, "PROCEEDINGS") ) 
	  strcpy(temp, "Proceedings   ");
        if ( strstr( holder, "TECHREPORT") ) 
	  strcpy(temp, "Tech Rerort   ");
        if ( strstr( holder, "UNPUBLISHED") ) 
	  strcpy(temp, "Unpublished   ");
	strcpy(type, temp);
	if ( start = strstr( holder, "{" ) ) 
	  if ( end = strstr( holder, "," ) )  {
	    *end = ' ';
	    end++;
	    *end = ' ';
	    end++;
	    *end = '\0';
  	    strcpy(tag, start+1);
	  }
	  else {
	    error(widget, GINT_TO_POINTER(9));
	    g_print("Format error in this BibTeX file - no ending ,");
	  }
	else  {
	  error(widget, GINT_TO_POINTER(9));
	  g_print("Format error in this BibTeX file - no {");
	}
      }
	                   /* if the line starts with 'year = {' */
      if ( start = strstr(holder, "  year = {") )  {
        end = strstr(holder, "}");
	*end = '\n';
	end++;
        *end = '\0';
	strcpy(temp, start+10);
	  gtk_text_buffer_insert_with_tags_by_name(textpad, &iter,
	                type, -1,
			"blackface", "point", "font", NULL);
	  gtk_text_buffer_insert_with_tags_by_name(textpad, &iter,
	                tag, -1,
			"emphasis", "point", "font", NULL);
	  gtk_text_buffer_insert_with_tags_by_name(textpad, &iter,
	                title, -1,
			"blackface", "point", "font", NULL);
	  gtk_text_buffer_insert_with_tags_by_name(textpad, &iter,
	                "   ", -1,
			"blackface", "point", "font", NULL);
	  gtk_text_buffer_insert_with_tags_by_name(textpad, &iter,
	                temp, -1,
			"target", "point", "font", NULL);
	count++;
      }
                               /* if the line starts with 'title = {' */
      if ( start = strstr( holder, "  title = {" ) )  {
        if ( end = strstr( holder, "}," )  ) {
	  if ( (end - start) > 60 )
	    end = start + 60;
	  *end = '\n';
	  end++;
	  *end = '\0';
	  start += 11;
	  strcpy(title, start);
	}
	else  {
	  error(widget, GINT_TO_POINTER(9));
	  g_print("Format error in this BibTeX file - no ending ,}");
	}
      }
    }
    else
      i++;
  }
  sprintf(report, "%d references displayed", count);
  gtk_entry_set_text(GTK_ENTRY(summary), report);
}