Added more batch functionality, including the CALL GOTO and SHIFT
[wine] / ipc / dde_proc_test.c
1 /***************************************************************************
2  * Copyright 1995, Technion, Israel Institute of Technology
3  * Electrical Eng, Software Lab.
4  * Author:    Michael Veksler.
5  ***************************************************************************
6  * File:      dde_proc.c
7  * Purpose :  test DDE signals and processes functionality for DDE
8  * Usage:     run two independant processes, one with an argument another
9  *            without (with the argument is the server).
10  ***************************************************************************
11  */
12 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
13 #include <sys/syscall.h>
14 #include <sys/param.h>
15 #else
16 #include <syscall.h>
17 #endif
18 #include <stdio.h>
19 #include <unistd.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <signal.h>
23 #include <win.h>
24 #include "dde.h"
25 #include "dde_proc.h"
26 #include "shm_main_blk.h"
27
28 #if !defined(BSD4_4) || defined(linux) || defined(__FreeBSD__)
29 char * cstack[4096];
30 #endif
31 #ifdef linux
32 extern void ___sig_restore();
33 extern void ___masksig_restore();
34
35 /* Similar to the sigaction function in libc, except it leaves alone the
36    restorer field */
37
38 static int
39 wine_sigaction(int sig,struct sigaction * new, struct sigaction * old)
40 {
41         __asm__("int $0x80":"=a" (sig)
42                 :"0" (SYS_sigaction),"b" (sig),"c" (new),"d" (old));
43         if (sig>=0)
44                 return 0;
45         errno = -sig;
46         return -1;
47 }
48 #endif
49
50 struct sigaction usr2_act;
51
52
53 void init_signals()
54 {
55 #ifdef linux
56   usr2_act.sa_handler = (__sighandler_t) stop_wait;
57   usr2_act.sa_flags = 0;
58   usr2_act.sa_restorer = 
59     (void (*)()) (((unsigned int)(cstack) + sizeof(cstack) - 4) & ~3);
60   wine_sigaction(SIGUSR2,&usr2_act,NULL);
61 #endif
62 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
63   usr2_act.sa_hadnler = (void (*)) stop_wait;
64   usr2_act.sa_flags = SA_ONSTACK;
65   usr2_act.sa_mask = sig_mask;
66   usr2_act.sa_restorer = 
67     (void (*)()) (((unsigned int)(cstack) + sizeof(cstack) - 4) & ~3);
68   if (sigaction(SIGUSR2,&usr2_act,NULL) <0) {
69      perror("sigaction: SIGUSR2");
70      exit(1);
71   }
72 #endif  
73 }
74 void ATOM_GlobalInit()
75 {
76   printf("ATOM_GlobalInit\n");
77 }
78
79
80 void idle_loop()
81 {
82   int timeout;
83   for(timeout=500; timeout ; timeout--) {
84      if (DDE_GetRemoteMessage())
85          exit(0); ;
86      usleep(1000);
87   }
88   exit(-1);
89 }
90
91 void client()
92 {
93   MSG msg;
94   msg.hwnd=(HWND)-1;
95   msg.message= WM_DDE_INITIATE;
96   msg.wParam= 3;
97   msg.lParam= 4;
98   if (!DDE_SendMessage(&msg))
99        exit(-1);
100   idle_loop();
101 }
102 void server()
103 {
104   DDE_IPC_init();
105   idle_loop();
106 }
107
108 int main(int argc, char *argv[])
109 {
110   printf("Kill when done one message\n");
111   init_signals();
112   if (argc>1)
113      server();
114   else
115      client();
116   return 0;
117 }