File: print.c

package info (click to toggle)
denemo 0.5.9-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,500 kB
  • ctags: 2,415
  • sloc: ansic: 23,057; sh: 3,321; yacc: 1,737; makefile: 449; lex: 376
file content (81 lines) | stat: -rw-r--r-- 1,706 bytes parent folder | download
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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>

#ifndef G_OS_WIN32
#include <wait.h>
#endif

#include <errno.h>

#include "print.h"
#include "prefops.h"
#include "exportmudela.h"
#include "utils.h"


/*  Print function 
 *  Save file in lilypond format
 *  Fork and run lilypond
 *  Fork and run tex
 *  Fork and run xdvi
 */
void
print(gpointer callback_data, guint callback_action, GtkWidget *widget)
{
  static GString *filename = NULL;
  static GString *passtosystem;
  pid_t pid;
  struct scoreinfo *si = (struct scoreinfo *) callback_data;

  if(!filename)
    {
       filename = g_string_new(locatedotdenemo ());
       g_string_append(filename, "/denemoprint");
       passtosystem = g_string_new(NULL);
    }

#ifdef G_OS_WIN32
  pid = -1;
#else
  pid = fork();
#endif

  if(pid == -1)
     {
	fprintf(stderr, "%s: Failed to fork()\n", strerror(errno));
	return;
     }
  else if(pid == 0)
     {
	exportmudela(filename->str,si, 0,0);
	g_string_assign(passtosystem, si->prefs->lilypath->str);
	g_string_append(passtosystem, " -o ");
	g_string_append(passtosystem, filename->str);
	g_string_append(passtosystem, " ");	
	g_string_append(passtosystem, filename->str);
	g_string_append(passtosystem, ".ly");
	
	if(system(passtosystem->str))
          _exit(0);
      	
     	g_string_assign(passtosystem, "tex ");
	g_string_append(passtosystem, filename->str);
	g_string_append(passtosystem, ".tex");
	if(system(passtosystem->str))
	  _exit(0);
	
     	g_string_assign(passtosystem, "xdvi ");
	g_string_append(passtosystem, filename->str);
	g_string_append(passtosystem, ".dvi");
	system("xdvi denemoprint.dvi");
     

	_exit(0);
     }

  
}