record.c revision fd7d9bd3
1fd7d9bd3Smrg/*
2fd7d9bd3Smrg** xgc
3fd7d9bd3Smrg**
4fd7d9bd3Smrg** record.c
5fd7d9bd3Smrg*/
6fd7d9bd3Smrg/* $XFree86: xc/programs/xgc/record.c,v 1.3 2000/02/17 14:00:37 dawes Exp $ */
7fd7d9bd3Smrg
8fd7d9bd3Smrg#include <X11/Intrinsic.h>
9fd7d9bd3Smrg#include <X11/StringDefs.h>
10fd7d9bd3Smrg#include <X11/Xaw/Label.h>
11fd7d9bd3Smrg#include <X11/Xaw/Command.h>
12fd7d9bd3Smrg#include <X11/Xaw/Form.h>
13fd7d9bd3Smrg#include <X11/Shell.h>
14fd7d9bd3Smrg#include <X11/Xaw/AsciiText.h>
15fd7d9bd3Smrg#include <stdio.h>
16fd7d9bd3Smrg
17fd7d9bd3Smrg#include "xgc.h"
18fd7d9bd3Smrg
19fd7d9bd3Smrgstatic void start_recording(void);
20fd7d9bd3Smrgstatic void stop_recording(void);
21fd7d9bd3Smrgstatic void print_out_gc_values(void);
22fd7d9bd3Smrgstatic void chose_playback_filename(void);
23fd7d9bd3Smrgstatic void cancel_playback(void);
24fd7d9bd3Smrgstatic void done_choosing_filename(void) ;
25fd7d9bd3Smrgstatic void cancel_record(void);
26fd7d9bd3Smrg
27fd7d9bd3SmrgFILE *recordfile;		/* the file we're recording to */
28fd7d9bd3SmrgFILE *playbackfile;		/* the file we're playing back from */
29fd7d9bd3Smrg
30fd7d9bd3Smrg/* toggle_recordbutton(w,closure,call_data)
31fd7d9bd3Smrg** ----------------------------------------
32fd7d9bd3Smrg** This function is called when the user presses the "Record"
33fd7d9bd3Smrg** command button.  If we're not recording, we start; if we are,
34fd7d9bd3Smrg** we stop.  Also change the label to reflect the change in the
35fd7d9bd3Smrg** function of the button.
36fd7d9bd3Smrg*/
37fd7d9bd3Smrg
38fd7d9bd3Smrg/*ARGSUSED*/
39fd7d9bd3Smrgvoid
40fd7d9bd3Smrgtoggle_recordbutton(Widget w, caddr_t closure, caddr_t call_data)
41fd7d9bd3Smrg{
42fd7d9bd3Smrg  /* ArgList for changing the label */
43fd7d9bd3Smrg  static Arg recordargs[] = {
44fd7d9bd3Smrg    {XtNlabel,        (XtArgVal) NULL}
45fd7d9bd3Smrg  };
46fd7d9bd3Smrg
47fd7d9bd3Smrg  char tmp[20];			/* new label */
48fd7d9bd3Smrg
49fd7d9bd3Smrg  if (!recording) {
50fd7d9bd3Smrg    start_recording();
51fd7d9bd3Smrg  }
52fd7d9bd3Smrg  else {
53fd7d9bd3Smrg    recording = FALSE;
54fd7d9bd3Smrg    stop_recording();
55fd7d9bd3Smrg    snprintf(tmp, sizeof tmp, "Record");
56fd7d9bd3Smrg    recordargs[0].value = (XtArgVal) tmp;
57fd7d9bd3Smrg  }
58fd7d9bd3Smrg
59fd7d9bd3Smrg  XtSetValues(recordbutton,recordargs,XtNumber(recordargs));
60fd7d9bd3Smrg}
61fd7d9bd3Smrg
62fd7d9bd3Smrg/* start_recording()
63fd7d9bd3Smrg** -----------------
64fd7d9bd3Smrg** Get the name of the file the user wants to record into, and
65fd7d9bd3Smrg** start recording into it if he doesn't cancel.
66fd7d9bd3Smrg*/
67fd7d9bd3Smrg
68fd7d9bd3Smrgstatic void
69fd7d9bd3Smrgstart_recording(void)
70fd7d9bd3Smrg{
71fd7d9bd3Smrg  get_filename(done_choosing_filename,cancel_record);
72fd7d9bd3Smrg}
73fd7d9bd3Smrg
74fd7d9bd3Smrg/* stop_recording()
75fd7d9bd3Smrg** ----------------
76fd7d9bd3Smrg** Close the output file.
77fd7d9bd3Smrg*/
78fd7d9bd3Smrg
79fd7d9bd3Smrgstatic void
80fd7d9bd3Smrgstop_recording(void)
81fd7d9bd3Smrg{
82fd7d9bd3Smrg  fclose(recordfile);
83fd7d9bd3Smrg}
84fd7d9bd3Smrg
85fd7d9bd3Smrg/* cancel_record()
86fd7d9bd3Smrg** ---------------
87fd7d9bd3Smrg** What to do if the if the user canceled recording, i.e. nothing.
88fd7d9bd3Smrg*/
89fd7d9bd3Smrg
90fd7d9bd3Smrgstatic void
91fd7d9bd3Smrgcancel_record(void)
92fd7d9bd3Smrg{
93fd7d9bd3Smrg}
94fd7d9bd3Smrg
95fd7d9bd3Smrg/* done_choosing_filename()
96fd7d9bd3Smrg** ------------------------
97fd7d9bd3Smrg** What to do after the user's chosen a file.  Change the label on the
98fd7d9bd3Smrg** command button, open the file, and dump the current contents of the
99fd7d9bd3Smrg** GC into it.
100fd7d9bd3Smrg*/
101fd7d9bd3Smrg
102fd7d9bd3Smrgstatic void
103fd7d9bd3Smrgdone_choosing_filename(void)
104fd7d9bd3Smrg{
105fd7d9bd3Smrg  static Arg recordargs[] = {
106fd7d9bd3Smrg    {XtNlabel,        (XtArgVal) NULL},
107fd7d9bd3Smrg    {XtNresize,       (XtArgVal) True}
108fd7d9bd3Smrg  };
109fd7d9bd3Smrg  Arg args[1];
110fd7d9bd3Smrg  char tmp[20], *filename;
111fd7d9bd3Smrg
112fd7d9bd3Smrg  XtSetArg(args[0], XtNstring, &filename);
113fd7d9bd3Smrg  XtGetValues(filename_text_widget, args, (Cardinal) 1);
114fd7d9bd3Smrg
115fd7d9bd3Smrg  if ((recordfile = fopen(filename,"w")) != NULL) {
116fd7d9bd3Smrg    recording = TRUE;
117fd7d9bd3Smrg    snprintf(tmp, sizeof tmp, "End Record");
118fd7d9bd3Smrg    recordargs[0].value = (XtArgVal) tmp;
119fd7d9bd3Smrg    XtSetValues(recordbutton,recordargs,XtNumber(recordargs));
120fd7d9bd3Smrg
121fd7d9bd3Smrg    print_out_gc_values();
122fd7d9bd3Smrg  }
123fd7d9bd3Smrg}
124fd7d9bd3Smrg
125fd7d9bd3Smrg/* print_if_recording(str)
126fd7d9bd3Smrg** -----------------------
127fd7d9bd3Smrg** If we're recording to a file, put str in it.
128fd7d9bd3Smrg*/
129fd7d9bd3Smrg
130fd7d9bd3Smrgvoid
131fd7d9bd3Smrgprint_if_recording(const char *str)
132fd7d9bd3Smrg{
133fd7d9bd3Smrg  if (recording)
134fd7d9bd3Smrg    fprintf(recordfile,"%s",str);
135fd7d9bd3Smrg}
136fd7d9bd3Smrg
137fd7d9bd3Smrg/* close_file_if_recording()
138fd7d9bd3Smrg** -------------------------
139fd7d9bd3Smrg** If we're recording, stop.
140fd7d9bd3Smrg*/
141fd7d9bd3Smrg
142fd7d9bd3Smrgvoid
143fd7d9bd3Smrgclose_file_if_recording(void)
144fd7d9bd3Smrg{
145fd7d9bd3Smrg  if (recording)
146fd7d9bd3Smrg    fclose(recordfile);
147fd7d9bd3Smrg}
148fd7d9bd3Smrg
149fd7d9bd3Smrg/* print_out_gc_values()
150fd7d9bd3Smrg** ---------------------
151fd7d9bd3Smrg** Dump the contents of the GC to the file, so that when the file gets
152fd7d9bd3Smrg** played back, it will be correctly initialized.
153fd7d9bd3Smrg*/
154fd7d9bd3Smrg
155fd7d9bd3Smrgstatic void
156fd7d9bd3Smrgprint_out_gc_values(void)
157fd7d9bd3Smrg{
158fd7d9bd3Smrg  int i;
159fd7d9bd3Smrg  for (i=0;i<NUM_TESTS;++i) {
160fd7d9bd3Smrg    if ((TestStuff.data)[i].code == X.test) {
161fd7d9bd3Smrg      fprintf(recordfile,"%s %s\n",
162fd7d9bd3Smrg	      TestStuff.choice.text,(TestStuff.data)[i].text);
163fd7d9bd3Smrg      break;
164fd7d9bd3Smrg    }
165fd7d9bd3Smrg  }
166fd7d9bd3Smrg  for (i=0;i<NUM_FUNCTIONS;++i) {
167fd7d9bd3Smrg    if ((FunctionStuff.data)[i].code == X.gcv.function) {
168fd7d9bd3Smrg      fprintf(recordfile,"%s %s\n",
169fd7d9bd3Smrg	      FunctionStuff.choice.text,(FunctionStuff.data)[i].text);
170fd7d9bd3Smrg      break;
171fd7d9bd3Smrg    }
172fd7d9bd3Smrg  }
173fd7d9bd3Smrg  for (i=0;i<NUM_LINESTYLES;++i) {
174fd7d9bd3Smrg    if ((LinestyleStuff.data)[i].code == X.gcv.line_style) {
175fd7d9bd3Smrg      fprintf(recordfile,"%s %s\n",
176fd7d9bd3Smrg	      LinestyleStuff.choice.text,(LinestyleStuff.data)[i].text);
177fd7d9bd3Smrg      break;
178fd7d9bd3Smrg    }
179fd7d9bd3Smrg  }
180fd7d9bd3Smrg  for (i=0;i<NUM_CAPSTYLES;++i) {
181fd7d9bd3Smrg    if ((CapstyleStuff.data)[i].code == X.gcv.cap_style) {
182fd7d9bd3Smrg      fprintf(recordfile,"%s %s\n",
183fd7d9bd3Smrg	      CapstyleStuff.choice.text,(CapstyleStuff.data)[i].text);
184fd7d9bd3Smrg      break;
185fd7d9bd3Smrg    }
186fd7d9bd3Smrg  }
187fd7d9bd3Smrg  for (i=0;i<NUM_JOINSTYLES;++i) {
188fd7d9bd3Smrg    if ((JoinstyleStuff.data)[i].code == X.gcv.join_style) {
189fd7d9bd3Smrg      fprintf(recordfile,"%s %s\n",
190fd7d9bd3Smrg	      JoinstyleStuff.choice.text,(JoinstyleStuff.data)[i].text);
191fd7d9bd3Smrg      break;
192fd7d9bd3Smrg    }
193fd7d9bd3Smrg  }
194fd7d9bd3Smrg  for (i=0;i<NUM_FILLSTYLES;++i) {
195fd7d9bd3Smrg    if ((FillstyleStuff.data)[i].code == X.gcv.fill_style) {
196fd7d9bd3Smrg      fprintf(recordfile,"%s %s\n",
197fd7d9bd3Smrg	      FillstyleStuff.choice.text,(FillstyleStuff.data)[i].text);
198fd7d9bd3Smrg      break;
199fd7d9bd3Smrg    }
200fd7d9bd3Smrg  }
201fd7d9bd3Smrg  for (i=0;i<NUM_FILLRULES;++i) {
202fd7d9bd3Smrg    if ((FillruleStuff.data)[i].code == X.gcv.fill_rule) {
203fd7d9bd3Smrg      fprintf(recordfile,"%s %s\n",
204fd7d9bd3Smrg	      FillruleStuff.choice.text,(FillruleStuff.data)[i].text);
205fd7d9bd3Smrg      break;
206fd7d9bd3Smrg    }
207fd7d9bd3Smrg  }
208fd7d9bd3Smrg  for (i=0;i<NUM_ARCMODES;++i) {
209fd7d9bd3Smrg    if ((ArcmodeStuff.data)[i].code == X.gcv.arc_mode) {
210fd7d9bd3Smrg      fprintf(recordfile,"%s %s\n",
211fd7d9bd3Smrg	      ArcmodeStuff.choice.text,(ArcmodeStuff.data)[i].text);
212fd7d9bd3Smrg      break;
213fd7d9bd3Smrg    }
214fd7d9bd3Smrg  }
215fd7d9bd3Smrg  fprintf(recordfile,"linewidth %d\n",X.gcv.line_width);
216fd7d9bd3Smrg  fprintf(recordfile,"foreground %ld\n",X.gcv.foreground);
217fd7d9bd3Smrg  fprintf(recordfile,"background %ld\n",X.gcv.background);
218fd7d9bd3Smrg  fprintf(recordfile,"planemask %ld\n",X.gcv.plane_mask);
219fd7d9bd3Smrg  fprintf(recordfile,"dashlist %d\n",X.gcv.dashes);
220fd7d9bd3Smrg  fprintf(recordfile,"font %s\n",X.fontname);
221fd7d9bd3Smrg}
222fd7d9bd3Smrg
223fd7d9bd3Smrg/********************************************/
224fd7d9bd3Smrg
225fd7d9bd3Smrg/* start_playback()
226fd7d9bd3Smrg** ----------------
227fd7d9bd3Smrg** This gets called if the user wants to playback from a file.
228fd7d9bd3Smrg** Get the file name and do the appropriate thing.
229fd7d9bd3Smrg*/
230fd7d9bd3Smrg
231fd7d9bd3Smrgvoid
232fd7d9bd3Smrgstart_playback(void)
233fd7d9bd3Smrg{
234fd7d9bd3Smrg  get_filename(chose_playback_filename,cancel_playback);
235fd7d9bd3Smrg}
236fd7d9bd3Smrg
237fd7d9bd3Smrg/* cancel_playback()
238fd7d9bd3Smrg** -----------------
239fd7d9bd3Smrg** What to do if the user canceled the playback request.
240fd7d9bd3Smrg*/
241fd7d9bd3Smrg
242fd7d9bd3Smrgstatic void
243fd7d9bd3Smrgcancel_playback(void)
244fd7d9bd3Smrg{
245fd7d9bd3Smrg}
246fd7d9bd3Smrg
247fd7d9bd3Smrg/* chose_playback_filename()
248fd7d9bd3Smrg** -------------------------
249fd7d9bd3Smrg** What to do once the user's selected a filename to playback.
250fd7d9bd3Smrg** Play it back.
251fd7d9bd3Smrg*/
252fd7d9bd3Smrg
253fd7d9bd3Smrgstatic void
254fd7d9bd3Smrgchose_playback_filename(void)
255fd7d9bd3Smrg{
256fd7d9bd3Smrg  Arg args[1];
257fd7d9bd3Smrg  char *filename;
258fd7d9bd3Smrg
259fd7d9bd3Smrg  XtSetArg(args[0], XtNstring, &filename);
260fd7d9bd3Smrg  XtGetValues(filename_text_widget, args, (Cardinal) 1);
261fd7d9bd3Smrg
262fd7d9bd3Smrg  if ((playbackfile = fopen(filename,"r")) != NULL) {
263fd7d9bd3Smrg    yyin = playbackfile;
264fd7d9bd3Smrg    yyparse();
265fd7d9bd3Smrg  }
266fd7d9bd3Smrg}
267fd7d9bd3Smrg
268fd7d9bd3Smrg/* read_from_keyboard()
269fd7d9bd3Smrg** --------------------
270fd7d9bd3Smrg** Do a playback from the keyboard.
271fd7d9bd3Smrg*/
272fd7d9bd3Smrg
273fd7d9bd3Smrgvoid
274fd7d9bd3Smrgread_from_keyboard(void)
275fd7d9bd3Smrg{
276fd7d9bd3Smrg  yyin = stdin;
277fd7d9bd3Smrg  yyparse();
278fd7d9bd3Smrg}
279