/* ** xgc ** ** record.c */ #include #include #include #include #include #include #include #include #include "xgc.h" static void start_recording(); static void stop_recording(); static void print_out_gc_values(); static void chose_playback_filename(); static void cancel_playback(); extern void get_filename(); extern XgcStuff TestStuff; extern XgcStuff FunctionStuff; extern XgcStuff LinestyleStuff; extern XgcStuff CapstyleStuff; extern XgcStuff JoinstyleStuff; extern XgcStuff FillstyleStuff; extern XgcStuff FillruleStuff; extern XgcStuff ArcmodeStuff; extern XStuff X; extern Boolean recording; extern Widget filename_text_widget, recordbutton; static void cancel_record(); static void done_choosing_filename(); FILE *recordfile; /* the file we're recording to */ FILE *playbackfile; /* the file we're playing back from */ extern FILE *yyin; /* for yyparse */ /* toggle_recordbutton(w,closure,call_data) ** ---------------------------------------- ** This function is called when the user presses the "Record" ** command button. If we're not recording, we start; if we are, ** we stop. Also change the label to reflect the change in the ** function of the button. */ /*ARGSUSED*/ void toggle_recordbutton(w,closure,call_data) Widget w; caddr_t closure; caddr_t call_data; { /* ArgList for changing the label */ static Arg recordargs[] = { {XtNlabel, (XtArgVal) NULL} }; char tmp[20]; /* new label */ if (!recording) { start_recording(); } else { recording = FALSE; stop_recording(); sprintf(tmp,"Record"); recordargs[0].value = (XtArgVal) tmp; } XtSetValues(recordbutton,recordargs,XtNumber(recordargs)); } /* start_recording() ** ----------------- ** Get the name of the file the user wants to record into, and ** start recording into it if he doesn't cancel. */ static void start_recording() { get_filename(done_choosing_filename,cancel_record); } /* stop_recording() ** ---------------- ** Close the output file. */ static void stop_recording() { fclose(recordfile); } /* cancel_record() ** --------------- ** What to do if the if the user canceled recording, i.e. nothing. */ static void cancel_record() { } /* done_choosing_filename() ** ------------------------ ** What to do after the user's chosen a file. Change the label on the ** command button, open the file, and dump the current contents of the ** GC into it. */ static void done_choosing_filename() { static Arg recordargs[] = { {XtNlabel, (XtArgVal) NULL}, {XtNresize, (XtArgVal) True} }; Arg args[1]; char tmp[20], *filename; XtSetArg(args[0], XtNstring, &filename); XtGetValues(filename_text_widget, args, (Cardinal) 1); if (recordfile = fopen(filename,"w")) { recording = TRUE; sprintf(tmp,"End Record"); recordargs[0].value = (XtArgVal) tmp; XtSetValues(recordbutton,recordargs,XtNumber(recordargs)); print_out_gc_values(); } } /* print_if_recording(str) ** ----------------------- ** If we're recording to a file, put str in it. */ void print_if_recording(str) char *str; { if (recording) fprintf(recordfile,"%s",str); } /* close_file_if_recording() ** ------------------------- ** If we're recording, stop. */ void close_file_if_recording() { if (recording) fclose(recordfile); } /* print_out_gc_values() ** --------------------- ** Dump the contents of the GC to the file, so that when the file gets ** played back, it will be correctly initialized. */ static void print_out_gc_values() { int i; for (i=0;i