my_scripts 0.1.5 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY CHANGED
@@ -31,3 +31,11 @@
31
31
  == 0.1.5 / 2010-04-17
32
32
 
33
33
  * Debugging wake
34
+
35
+ == 0.1.6 / 2010-04-17
36
+
37
+ * Msdn added
38
+
39
+ == 0.1.7 / 2010-04-29
40
+
41
+ * Msdn helper extracted - for RubyMine script
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.1.7
data/bin/msdn ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + '/../lib/my_scripts'
4
+
5
+ MyScripts::CLI.run :msdn, ARGV
@@ -12,8 +12,8 @@ module MyScripts
12
12
 
13
13
  # Instantiates new CLI(command line interface) and runs script with given name (token)
14
14
  # and argv inside new CLI instance
15
- def self.run( script_name, argv )
16
- new.run script_name, argv
15
+ def self.run( script_name, argv, argf=ARGF )
16
+ new.run script_name, argv, argf
17
17
  end
18
18
 
19
19
  # Creates new command line interface
@@ -24,11 +24,11 @@ module MyScripts
24
24
  end
25
25
 
26
26
  # Runs a script with given name (token) and argv inside this CLI instance
27
- def run( script_name, argv )
27
+ def run( script_name, argv, argf=ARGF )
28
28
  script = script_class_name(script_name).to_class
29
29
  raise ScriptNameError.new("Script #{script_class_name(script_name)} not found") unless script
30
30
 
31
- script.new(script_name, argv, self).run
31
+ script.new(script_name, self, argv, argf).run
32
32
  end
33
33
 
34
34
  private
@@ -2,10 +2,11 @@ module MyScripts
2
2
  # Base class for all scripts. Subclass it and override run method with actual
3
3
  # work your script will be doing
4
4
  class Script
5
- def initialize( name, argv, cli )
5
+ def initialize( name, cli, argv, argf )
6
6
  @name = name
7
- @argv = argv
8
7
  @cli = cli
8
+ @argv = argv
9
+ @argf = argf
9
10
  end
10
11
 
11
12
  def version
@@ -0,0 +1,149 @@
1
+ # Make sure Strings respond to snake_case (even if this helper is called out of containing lib context)
2
+ # This is needed when this file is required by RubyMine script "msdn_converter.rb"
3
+ unless "".respond_to? :snake_case
4
+ class String
5
+ def snake_case
6
+ self.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
7
+ gsub(/([a-z\d])([A-Z])/, '\1_\2').
8
+ tr("-", "_").downcase
9
+ end
10
+ end
11
+ end
12
+
13
+ module MyScripts
14
+
15
+ module MsdnHelper
16
+
17
+ def self.convert(text, page_margin=6, page_width=110)
18
+ # Removing extra lines and spaces
19
+ text.gsub! /(^\s*|\r)/m, ""
20
+
21
+ # Extracting original function/struct syntax (definition)
22
+ syntax = text[/^Syntax.*?(}|\)).*?;/m]
23
+
24
+ if syntax =~ /typedef struct/ # this is a struct description
25
+ type = :struct
26
+
27
+ name = syntax.match(/}\s*([\w*]*)/m)[1] # first word after }
28
+ params = syntax.scan(/\s(\w*)\s # member type is a first word, followed by whitespace
29
+ (\*?[\w]*) # followed by member name
30
+ (?:\[([\w]*)\])? # POSSIBLY followed by [array dimension] ( it may be number or CONST)
31
+ (?:\s*?;)/mx) # ending with a semi-colon
32
+
33
+ # Creating different representations of struct syntax
34
+ ffi_params = params.map{|p| ":#{p[1].snake_case}, " + (p[2] ? "[:#{p[0]}, #{p[2]}]" : ":#{p[0]}")}.
35
+ join(",\n ")
36
+ ffi_syntax = "\nclass #{name} < FFI::Struct\n layout #{ffi_params}\nend\n"
37
+
38
+ original_params = params.map{|p| "#{p[0]} #{p[1]}" + (p[2] ? "[#{p[2]}]" : "")}.join("; ")
39
+ original_syntax = "[*Typedef*] struct { #{original_params} } #{name};"
40
+
41
+ elsif syntax =~ /.\(.*\);/m # this is a function descriptions
42
+ type = :function
43
+
44
+ returns, name = syntax.match(/(\w*\*?|\w*\*? \w*\*?) (\w*)\(/m)[1..2]
45
+ params = syntax.scan(/\s(\w*\*?) (\w*)(?:,|\s*\);)/m)
46
+
47
+ # Creating different representations of method(function) syntax
48
+ ffi_params = params.map{|p| ":" + p.first}.join(", ")
49
+ ffi_returns = returns =~ /BOOL/ ? ":int8, boolean: true" : ":#{returns}"
50
+ ffi_syntax = "function :#{name}, [#{ffi_params}], #{ffi_returns}"
51
+
52
+ original_params = params.empty? ? 'void' : params.map{|p| p.join(" ")}.join(", ")
53
+ original_syntax = "[*Syntax*] #{returns} #{name}( #{original_params} );"
54
+
55
+ call_syntax = "success = #{name.snake_case}(#{params.map{|p| p.last.snake_case}.join(", ")})"
56
+ snake_syntax = "success = #{name.snake_case}(#{params.map{|p| "#{p.last.snake_case}=0"}.join(", ")})"
57
+ camel_syntax = "success = #{name}(#{params.map{|p| "#{p.last.snake_case}=0"}.join(", ")})"
58
+
59
+ # Adding Enhanced API description and :call-seq: directive
60
+ text += "\n---\n<b>Enhanced (snake_case) API: </b>"
61
+ text += "\n\n:call-seq:\n #{call_syntax}\n \n"
62
+
63
+ else
64
+ type = :unknown
65
+ return 'Unknown syntax. Only functions and structs are converted.'
66
+ end
67
+
68
+ # Formatting params/members into two column table
69
+ params.each {|p| text.gsub!(Regexp.new("^#{p[1]}\n"), "#{p[1]}:: ")}
70
+
71
+ # Replacing MSDN idioms with RDoc ones, cutting some slack, adding extra info
72
+ replace = {
73
+ /^Syntax.*?(}|\)).*?;/m => "\n#{original_syntax}",
74
+ /^Parameters\s*/m => "\n",
75
+ /^Members\s*/m => "\n",
76
+ /^Return Value\n\s*/m => "\n*Returns*:: ",
77
+ /^Remarks\s*/m => "---\n*Remarks*:\n",
78
+ }
79
+ replace.each {|from, to| text.gsub!( from, to)}
80
+
81
+ # Chopping long lines into smaller ones (while keeping indent)
82
+ text_width = page_width - page_margin - 2
83
+ lines = []
84
+ text.split("\n").each do |line|
85
+ list_label = line.match(/:: |^\[.*?\] /)
86
+ indent = list_label ? list_label.end(0) : 0
87
+
88
+ first_pattern = Regexp.new ".{1,#{text_width}}(?: |$)"
89
+ chunk_pattern = Regexp.new ".{1,#{text_width - indent}}(?: |$)"
90
+ if line.length < text_width || indent > text_width || !(first_chunk = line.match(first_pattern))
91
+ lines << line
92
+ else
93
+ lines << first_chunk[0]
94
+ line[first_chunk.end(0)..-1].scan(chunk_pattern).each do |chunk|
95
+ lines << " " * indent + chunk
96
+ end
97
+ end
98
+ end
99
+ text = lines.join("\n")
100
+
101
+ # Inserting initial white spaces with comment sign
102
+ tab = " " * page_margin
103
+ text.gsub! /^(?!##)/m, tab + "# "
104
+
105
+ # Closing off with ffi syntax definition
106
+ text += "\n#{tab}#{ffi_syntax}"
107
+
108
+ if type == :function
109
+ # Prepending function with RDoc meta-method hint
110
+ text = "#{tab}##\n#{text}"
111
+
112
+ # Extracting description
113
+ description = text[Regexp.new "(?<=(?:^F|f)unction\\s).{1,#{text_width}}(?: |$)"]
114
+
115
+ # Adding Rspec examples
116
+ text += %Q[
117
+
118
+ describe "##{name.snake_case}" do
119
+ spec{ use{ #{camel_syntax} }}
120
+ spec{ use{ #{snake_syntax} }}
121
+
122
+ it "original api #{description}" do
123
+ pending
124
+ #{camel_syntax}
125
+ end
126
+
127
+ it "snake_case api #{description}" do
128
+ pending
129
+ #{snake_syntax}
130
+ end
131
+
132
+ end # describe #{name.snake_case}\n]
133
+ end
134
+
135
+ text
136
+ end
137
+
138
+ end
139
+ end
140
+
141
+ # if this script file is called directly, convert given file (default test.txt) to stdout
142
+ if __FILE__ == $0
143
+ test_file = ARGV[0] || 'test.txt' # File.expand_path(File.dirname(__FILE__) + '/test')
144
+ File.open(test_file) do |f|
145
+ puts MyScripts::MsdnHelper.convert f.readlines.join("\n")
146
+ end
147
+ end
148
+
149
+
@@ -0,0 +1,19 @@
1
+ module MyScripts
2
+
3
+ # This script converts text copied from MSND function or struct description
4
+ # into RDoc-compatible comment format. It also adds function and spec stub
5
+ # (both are used by Win gem). This reduces dramatically amount of manual work
6
+ # needed to convert MSDN info into RDoc
7
+ #
8
+ class Msdn < Script
9
+ VERSION = '0.0.1'
10
+
11
+ def run
12
+ usage "[in_file] File containing MSDN text (reads from stdin if no infile)" if @argv.size > 1
13
+
14
+ puts MsdnHelper.convert @argf.read
15
+ end
16
+
17
+
18
+ end
19
+ end
@@ -0,0 +1,100 @@
1
+ DdeInitialize Function
2
+
3
+ --------------------------------------------------------------------------------
4
+
5
+ The DdeInitialize function registers an application with the Dynamic Data Exchange Management Library (DDEML). An application must call this function before calling any other Dynamic Data Exchange Management Library (DDEML) function.
6
+
7
+ Syntax
8
+
9
+ UINT DdeInitialize( LPDWORD pidInst,
10
+ PFNCALLBACK pfnCallback,
11
+ DWORD afCmd,
12
+ DWORD ulRes
13
+ );
14
+ Parameters
15
+
16
+ pidInst
17
+ [in, out] Pointer to the application instance identifier. At initialization, this parameter should point to 0. If the function succeeds, this parameter points to the instance identifier for the application. This value should be passed as the idInst parameter in all other DDEML functions that require it. If an application uses multiple instances of the DDEML dynamic-link library (DLL), the application should provide a different callback function for each instance.
18
+ If pidInst points to a nonzero value, reinitialization of the DDEML is implied. In this case, pidInst must point to a valid application-instance identifier.
19
+
20
+ pfnCallback
21
+ [in] Pointer to the application-defined Dynamic Data Exchange (DDE) callback function. This function processes DDE transactions sent by the system. For more information, see the DdeCallback callback function.
22
+ afCmd
23
+ [in] Specifies a set of APPCMD_, CBF_, and MF_ flags. The APPCMD_ flags provide special instructions to DdeInitialize. The CBF_ flags specify filters that prevent specific types of transactions from reaching the callback function. The MF_ flags specify the types of DDE activity that a DDE monitoring application monitors. Using these flags enhances the performance of a DDE application by eliminating unnecessary calls to the callback function.
24
+ This parameter can be one or more of the following values.
25
+
26
+ APPCLASS_MONITOR
27
+ Makes it possible for the application to monitor DDE activity in the system. This flag is for use by DDE monitoring applications. The application specifies the types of DDE activity to monitor by combining one or more monitor flags with the APPCLASS_MONITOR flag. For details, see the following Remarks section.
28
+ APPCLASS_STANDARD
29
+ Registers the application as a standard (nonmonitoring) DDEML application.
30
+ APPCMD_CLIENTONLY
31
+ Prevents the application from becoming a server in a DDE conversation. The application can only be a client. This flag reduces consumption of resources by the DDEML. It includes the functionality of the CBF_FAIL_ALLSVRXACTIONS flag.
32
+ APPCMD_FILTERINITS
33
+ Prevents the DDEML from sending XTYP_CONNECT and XTYP_WILDCONNECT transactions to the application until the application has created its string handles and registered its service names or has turned off filtering by a subsequent call to the DdeNameService or DdeInitialize function. This flag is always in effect when an application calls DdeInitialize for the first time, regardless of whether the application specifies the flag. On subsequent calls to DdeInitialize, not specifying this flag turns off the application's service-name filters, but specifying it turns on the application's service name filters.
34
+ CBF_FAIL_ALLSVRXACTIONS
35
+ Prevents the callback function from receiving server transactions. The system returns DDE_FNOTPROCESSED to each client that sends a transaction to this application. This flag is equivalent to combining all CBF_FAIL_ flags.
36
+ CBF_FAIL_ADVISES
37
+ Prevents the callback function from receiving XTYP_ADVSTART and XTYP_ADVSTOP transactions. The system returns DDE_FNOTPROCESSED to each client that sends an XTYP_ADVSTART or XTYP_ADVSTOP transaction to the server.
38
+ CBF_FAIL_CONNECTIONS
39
+ Prevents the callback function from receiving XTYP_CONNECT and XTYP_WILDCONNECT transactions.
40
+ CBF_FAIL_EXECUTES
41
+ Prevents the callback function from receiving XTYP_EXECUTE transactions. The system returns DDE_FNOTPROCESSED to a client that sends an XTYP_EXECUTE transaction to the server.
42
+ CBF_FAIL_POKES
43
+ Prevents the callback function from receiving XTYP_POKE transactions. The system returns DDE_FNOTPROCESSED to a client that sends an XTYP_POKE transaction to the server.
44
+ CBF_FAIL_REQUESTS
45
+ Prevents the callback function from receiving XTYP_REQUEST transactions. The system returns DDE_FNOTPROCESSED to a client that sends an XTYP_REQUEST transaction to the server.
46
+ CBF_FAIL_SELFCONNECTIONS
47
+ Prevents the callback function from receiving XTYP_CONNECT transactions from the application's own instance. This flag prevents an application from establishing a DDE conversation with its own instance. An application should use this flag if it needs to communicate with other instances of itself but not with itself.
48
+ CBF_SKIP_ALLNOTIFICATIONS
49
+ Prevents the callback function from receiving any notifications. This flag is equivalent to combining all CBF_SKIP_ flags.
50
+ CBF_SKIP_CONNECT_CONFIRMS
51
+ Prevents the callback function from receiving XTYP_CONNECT_CONFIRM notifications.
52
+ CBF_SKIP_DISCONNECTS
53
+ Prevents the callback function from receiving XTYP_DISCONNECT notifications.
54
+ CBF_SKIP_REGISTRATIONS
55
+ Prevents the callback function from receiving XTYP_REGISTER notifications.
56
+ CBF_SKIP_UNREGISTRATIONS
57
+ Prevents the callback function from receiving XTYP_UNREGISTER notifications.
58
+ MF_CALLBACKS
59
+ Notifies the callback function whenever a transaction is sent to any DDE callback function in the system.
60
+ MF_CONV
61
+ Notifies the callback function whenever a conversation is established or terminated.
62
+ MF_ERRORS
63
+ Notifies the callback function whenever a DDE error occurs.
64
+ MF_HSZ_INFO
65
+ Notifies the callback function whenever a DDE application creates, frees, or increments the usage count of a string handle or whenever a string handle is freed as a result of a call to the DdeUninitialize function.
66
+ MF_LINKS
67
+ Notifies the callback function whenever an advise loop is started or ended.
68
+ MF_POSTMSGS
69
+ Notifies the callback function whenever the system or an application posts a DDE message.
70
+ MF_SENDMSGS
71
+ Notifies the callback function whenever the system or an application sends a DDE message.
72
+ ulRes
73
+ Reserved; must be set to zero.
74
+ Return Value
75
+
76
+
77
+ If the function succeeds, the return value is DMLERR_NO_ERROR.
78
+
79
+ If the function fails, the return value is one of the following values:
80
+
81
+
82
+ DMLERR_DLL_USAGE
83
+ DMLERR_INVALIDPARAMETER
84
+ DMLERR_SYS_ERROR
85
+
86
+
87
+
88
+ Remarks
89
+
90
+ An application that uses multiple instances of the DDEML must not pass DDEML objects between instances.
91
+
92
+ A DDE monitoring application should not attempt to perform DDE operations (establish conversations, issue transactions, and so on) within the context of the same application instance.
93
+
94
+ A synchronous transaction fails with a DMLERR_REENTRANCY error if any instance of the same task has a synchronous transaction already in progress.
95
+
96
+ The CBF_FAIL_ALLSVRXACTIONS flag causes the DDEML to filter all server transactions and can be changed by a subsequent call to DdeInitialize. The APPCMD_CLIENTONLY flag prevents the DDEML from creating key resources for the server and cannot be changed by a subsequent call to DdeInitialize.
97
+
98
+ There is an ANSI version and a Unicode version of DdeInitialize. The version called determines the type of the window procedures used to control DDE conversations (ANSI or Unicode), and the default value for the iCodePage member of the CONVCONTEXT structure (CP_WINANSI or CP_WINUNICODE).
99
+
100
+ Windows 95/98/Me: DdeInitializeW is supported by the Microsoft Layer for Unicode (MSLU). To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems .
@@ -0,0 +1,145 @@
1
+ ##
2
+ # DdeInitialize Function
3
+ # --------------------------------------------------------------------------------
4
+ # The DdeInitialize function registers an application with the Dynamic Data Exchange Management Library
5
+ # (DDEML). An application must call this function before calling any other Dynamic Data Exchange
6
+ # Management Library (DDEML) function.
7
+ #
8
+ # [*Syntax*] UINT DdeInitialize( LPDWORD pidInst, PFNCALLBACK pfnCallback, DWORD afCmd, DWORD ulRes );
9
+ #
10
+ # pidInst:: [in, out] Pointer to the application instance identifier. At initialization, this parameter
11
+ # should point to 0. If the function succeeds, this parameter points to the instance
12
+ # identifier for the application. This value should be passed as the idInst parameter in all
13
+ # other DDEML functions that require it. If an application uses multiple instances of the
14
+ # DDEML dynamic-link library (DLL), the application should provide a different callback
15
+ # function for each instance.
16
+ # If pidInst points to a nonzero value, reinitialization of the DDEML is implied. In this case, pidInst
17
+ # must point to a valid application-instance identifier.
18
+ # pfnCallback:: [in] Pointer to the application-defined Dynamic Data Exchange (DDE) callback function.
19
+ # This function processes DDE transactions sent by the system. For more information, see
20
+ # the DdeCallback callback function.
21
+ # afCmd:: [in] Specifies a set of APPCMD_, CBF_, and MF_ flags. The APPCMD_ flags provide special
22
+ # instructions to DdeInitialize. The CBF_ flags specify filters that prevent specific types of
23
+ # transactions from reaching the callback function. The MF_ flags specify the types of DDE
24
+ # activity that a DDE monitoring application monitors. Using these flags enhances the
25
+ # performance of a DDE application by eliminating unnecessary calls to the callback function.
26
+ # This parameter can be one or more of the following values.
27
+ # APPCLASS_MONITOR
28
+ # Makes it possible for the application to monitor DDE activity in the system. This flag is for use by
29
+ # DDE monitoring applications. The application specifies the types of DDE activity to monitor by
30
+ # combining one or more monitor flags with the APPCLASS_MONITOR flag. For details, see the following
31
+ # Remarks section.
32
+ # APPCLASS_STANDARD
33
+ # Registers the application as a standard (nonmonitoring) DDEML application.
34
+ # APPCMD_CLIENTONLY
35
+ # Prevents the application from becoming a server in a DDE conversation. The application can only be a
36
+ # client. This flag reduces consumption of resources by the DDEML. It includes the functionality of the
37
+ # CBF_FAIL_ALLSVRXACTIONS flag.
38
+ # APPCMD_FILTERINITS
39
+ # Prevents the DDEML from sending XTYP_CONNECT and XTYP_WILDCONNECT transactions to the application
40
+ # until the application has created its string handles and registered its service names or has turned
41
+ # off filtering by a subsequent call to the DdeNameService or DdeInitialize function. This flag is
42
+ # always in effect when an application calls DdeInitialize for the first time, regardless of whether the
43
+ # application specifies the flag. On subsequent calls to DdeInitialize, not specifying this flag turns
44
+ # off the application's service-name filters, but specifying it turns on the application's service name
45
+ # filters.
46
+ # CBF_FAIL_ALLSVRXACTIONS
47
+ # Prevents the callback function from receiving server transactions. The system returns
48
+ # DDE_FNOTPROCESSED to each client that sends a transaction to this application. This flag is equivalent
49
+ # to combining all CBF_FAIL_ flags.
50
+ # CBF_FAIL_ADVISES
51
+ # Prevents the callback function from receiving XTYP_ADVSTART and XTYP_ADVSTOP transactions. The system
52
+ # returns DDE_FNOTPROCESSED to each client that sends an XTYP_ADVSTART or XTYP_ADVSTOP transaction to
53
+ # the server.
54
+ # CBF_FAIL_CONNECTIONS
55
+ # Prevents the callback function from receiving XTYP_CONNECT and XTYP_WILDCONNECT transactions.
56
+ # CBF_FAIL_EXECUTES
57
+ # Prevents the callback function from receiving XTYP_EXECUTE transactions. The system returns
58
+ # DDE_FNOTPROCESSED to a client that sends an XTYP_EXECUTE transaction to the server.
59
+ # CBF_FAIL_POKES
60
+ # Prevents the callback function from receiving XTYP_POKE transactions. The system returns
61
+ # DDE_FNOTPROCESSED to a client that sends an XTYP_POKE transaction to the server.
62
+ # CBF_FAIL_REQUESTS
63
+ # Prevents the callback function from receiving XTYP_REQUEST transactions. The system returns
64
+ # DDE_FNOTPROCESSED to a client that sends an XTYP_REQUEST transaction to the server.
65
+ # CBF_FAIL_SELFCONNECTIONS
66
+ # Prevents the callback function from receiving XTYP_CONNECT transactions from the application's own
67
+ # instance. This flag prevents an application from establishing a DDE conversation with its own
68
+ # instance. An application should use this flag if it needs to communicate with other instances of
69
+ # itself but not with itself.
70
+ # CBF_SKIP_ALLNOTIFICATIONS
71
+ # Prevents the callback function from receiving any notifications. This flag is equivalent to combining
72
+ # all CBF_SKIP_ flags.
73
+ # CBF_SKIP_CONNECT_CONFIRMS
74
+ # Prevents the callback function from receiving XTYP_CONNECT_CONFIRM notifications.
75
+ # CBF_SKIP_DISCONNECTS
76
+ # Prevents the callback function from receiving XTYP_DISCONNECT notifications.
77
+ # CBF_SKIP_REGISTRATIONS
78
+ # Prevents the callback function from receiving XTYP_REGISTER notifications.
79
+ # CBF_SKIP_UNREGISTRATIONS
80
+ # Prevents the callback function from receiving XTYP_UNREGISTER notifications.
81
+ # MF_CALLBACKS
82
+ # Notifies the callback function whenever a transaction is sent to any DDE callback function in the
83
+ # system.
84
+ # MF_CONV
85
+ # Notifies the callback function whenever a conversation is established or terminated.
86
+ # MF_ERRORS
87
+ # Notifies the callback function whenever a DDE error occurs.
88
+ # MF_HSZ_INFO
89
+ # Notifies the callback function whenever a DDE application creates, frees, or increments the usage
90
+ # count of a string handle or whenever a string handle is freed as a result of a call to the
91
+ # DdeUninitialize function.
92
+ # MF_LINKS
93
+ # Notifies the callback function whenever an advise loop is started or ended.
94
+ # MF_POSTMSGS
95
+ # Notifies the callback function whenever the system or an application posts a DDE message.
96
+ # MF_SENDMSGS
97
+ # Notifies the callback function whenever the system or an application sends a DDE message.
98
+ # ulRes:: Reserved; must be set to zero.
99
+ #
100
+ # *Returns*:: If the function succeeds, the return value is DMLERR_NO_ERROR.
101
+ # If the function fails, the return value is one of the following values:
102
+ # DMLERR_DLL_USAGE
103
+ # DMLERR_INVALIDPARAMETER
104
+ # DMLERR_SYS_ERROR
105
+ # ---
106
+ # *Remarks*:
107
+ # An application that uses multiple instances of the DDEML must not pass DDEML objects between
108
+ # instances.
109
+ # A DDE monitoring application should not attempt to perform DDE operations (establish conversations,
110
+ # issue transactions, and so on) within the context of the same application instance.
111
+ # A synchronous transaction fails with a DMLERR_REENTRANCY error if any instance of the same task has a
112
+ # synchronous transaction already in progress.
113
+ # The CBF_FAIL_ALLSVRXACTIONS flag causes the DDEML to filter all server transactions and can be changed
114
+ # by a subsequent call to DdeInitialize. The APPCMD_CLIENTONLY flag prevents the DDEML from creating key
115
+ # resources for the server and cannot be changed by a subsequent call to DdeInitialize.
116
+ # There is an ANSI version and a Unicode version of DdeInitialize. The version called determines the
117
+ # type of the window procedures used to control DDE conversations (ANSI or Unicode), and the default
118
+ # value for the iCodePage member of the CONVCONTEXT structure (CP_WINANSI or CP_WINUNICODE).
119
+ # Windows 95/98/Me: DdeInitializeW is supported by the Microsoft Layer for Unicode (MSLU). To use this,
120
+ # you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows
121
+ # 95/98/Me Systems .
122
+ #
123
+ # ---
124
+ # <b>Enhanced (snake_case) API: </b>
125
+ #
126
+ # :call-seq:
127
+ # success = dde_initialize(pid_inst, pfn_callback, af_cmd, ul_res)
128
+ #
129
+ function :DdeInitialize, [:LPDWORD, :PFNCALLBACK, :DWORD, :DWORD], :UINT
130
+
131
+ describe "#dde_initialize" do
132
+ spec{ use{ success = DdeInitialize(pid_inst=0, pfn_callback=0, af_cmd=0, ul_res=0) }}
133
+ spec{ use{ success = dde_initialize(pid_inst=0, pfn_callback=0, af_cmd=0, ul_res=0) }}
134
+
135
+ it "original api registers an application with the Dynamic Data Exchange Management Library " do
136
+ pending
137
+ success = DdeInitialize(pid_inst=0, pfn_callback=0, af_cmd=0, ul_res=0)
138
+ end
139
+
140
+ it "snake_case api registers an application with the Dynamic Data Exchange Management Library " do
141
+ pending
142
+ success = dde_initialize(pid_inst=0, pfn_callback=0, af_cmd=0, ul_res=0)
143
+ end
144
+
145
+ end # describe dde_initialize
@@ -0,0 +1,27 @@
1
+ The MSG structure contains message information from a thread's message queue.
2
+
3
+ Syntax
4
+
5
+ typedef struct {
6
+ HWND hwnd;
7
+ UINT message;
8
+ WPARAM wParam;
9
+ LPARAM lParam;
10
+ DWORD time;
11
+ POINT pt;
12
+ } MSG, *PMSG;
13
+ Members
14
+
15
+ hwnd
16
+ Handle to the window whose window procedure receives the message. hwnd is NULL when the message is a thread message.
17
+ message
18
+ Specifies the message identifier. Applications can only use the low word; the high word is reserved by the system.
19
+ wParam
20
+ Specifies additional information about the message. The exact meaning depends on the value of the message member.
21
+ lParam
22
+ Specifies additional information about the message. The exact meaning depends on the value of the message member.
23
+ time
24
+ Specifies the time at which the message was posted.
25
+ pt
26
+ Specifies the cursor position, in screen coordinates, when the message was posted.
27
+ --------
@@ -0,0 +1,25 @@
1
+ # The MSG structure contains message information from a thread's message queue.
2
+ #
3
+ # [*Typedef*] struct { HWND hwnd; UINT message; WPARAM wParam; LPARAM lParam; DWORD time; POINT pt }
4
+ # MSG;
5
+ #
6
+ # hwnd:: Handle to the window whose window procedure receives the message. hwnd is NULL when the message
7
+ # is a thread message.
8
+ # message:: Specifies the message identifier. Applications can only use the low word; the high word is
9
+ # reserved by the system.
10
+ # wParam:: Specifies additional information about the message. The exact meaning depends on the value of
11
+ # the message member.
12
+ # lParam:: Specifies additional information about the message. The exact meaning depends on the value of
13
+ # the message member.
14
+ # time:: Specifies the time at which the message was posted.
15
+ # pt:: Specifies the cursor position, in screen coordinates, when the message was posted.
16
+ # --------
17
+
18
+ class MSG < FFI::Struct
19
+ layout :hwnd, :HWND,
20
+ :message, :UINT,
21
+ :w_param, :WPARAM,
22
+ :l_param, :LPARAM,
23
+ :time, :DWORD,
24
+ :pt, :POINT
25
+ end
@@ -0,0 +1,41 @@
1
+ The MONCONVSTRUCT structure contains information about a Dynamic Data Exchange (DDE) conversation. A DDE monitoring application can use this structure to obtain information about a conversation that has been established or has terminated.
2
+
3
+ Syntax
4
+
5
+ typedef struct tagMONCONVSTRUCT {
6
+ UINT cb;
7
+ BOOL fConnect;
8
+ DWORD dwTime;
9
+ HANDLE hTask;
10
+ HSZ hszSvc;
11
+ HSZ hszTopic;
12
+ HCONV hConvClient;
13
+ HCONV hConvServer;
14
+ } MONCONVSTRUCT, *PMONCONVSTRUCT;
15
+ Members
16
+
17
+ cb
18
+ Specifies the structure's size, in bytes.
19
+ fConnect
20
+ Indicates whether the conversation is currently established. A value of TRUE indicates the conversation is established; FALSE indicates it is not.
21
+ dwTime
22
+ Specifies the Windows time at which the conversation was established or terminated. Windows time is the number of milliseconds that have elapsed since the system was booted.
23
+ hTask
24
+ Handle to a task (application instance) that is a partner in the conversation.
25
+ hszSvc
26
+ Handle to the service name on which the conversation is established.
27
+ hszTopic
28
+ Handle to the topic name on which the conversation is established.
29
+ hConvClient
30
+ Handle to the client conversation.
31
+ hConvServer
32
+ Handle to the server conversation.
33
+ Remarks
34
+
35
+ Because string handles are local to the process, the hszSvc and hszTopic members are global atoms. Similarly, conversation handles are local to the instance; therefore, the hConvClient and hConvServer members are window handles.
36
+
37
+ The hConvClient and hConvServer members of the MONCONVSTRUCT structure do not hold the same value as would be seen by the applications engaged in the conversation. Instead, they hold a globally unique pair of values that identify the conversation.
38
+
39
+ Structure Information
40
+
41
+ Header Declared in Ddeml.h, include Windows.h
@@ -0,0 +1,38 @@
1
+ # The MONCONVSTRUCT structure contains information about a Dynamic Data Exchange (DDE) conversation. A
2
+ # DDE monitoring application can use this structure to obtain information about a conversation that has
3
+ # been established or has terminated.
4
+ #
5
+ # [*Typedef*] struct { UINT cb; BOOL fConnect; DWORD dwTime; HANDLE hTask; HSZ hszSvc; HSZ hszTopic;
6
+ # HCONV hConvClient; HCONV hConvServer } MONCONVSTRUCT;
7
+ #
8
+ # cb:: Specifies the structure's size, in bytes.
9
+ # fConnect:: Indicates whether the conversation is currently established. A value of TRUE indicates the
10
+ # conversation is established; FALSE indicates it is not.
11
+ # dwTime:: Specifies the Windows time at which the conversation was established or terminated. Windows
12
+ # time is the number of milliseconds that have elapsed since the system was booted.
13
+ # hTask:: Handle to a task (application instance) that is a partner in the conversation.
14
+ # hszSvc:: Handle to the service name on which the conversation is established.
15
+ # hszTopic:: Handle to the topic name on which the conversation is established.
16
+ # hConvClient:: Handle to the client conversation.
17
+ # hConvServer:: Handle to the server conversation.
18
+ # ---
19
+ # *Remarks*:
20
+ # Because string handles are local to the process, the hszSvc and hszTopic members are global atoms.
21
+ # Similarly, conversation handles are local to the instance; therefore, the hConvClient and hConvServer
22
+ # members are window handles.
23
+ # The hConvClient and hConvServer members of the MONCONVSTRUCT structure do not hold the same value as
24
+ # would be seen by the applications engaged in the conversation. Instead, they hold a globally unique
25
+ # pair of values that identify the conversation.
26
+ # Structure Information
27
+ # Header Declared in Ddeml.h, include Windows.h
28
+
29
+ class MONCONVSTRUCT < FFI::Struct
30
+ layout :cb, :UINT,
31
+ :f_connect, :BOOL,
32
+ :dw_time, :DWORD,
33
+ :h_task, :HANDLE,
34
+ :hsz_svc, :HSZ,
35
+ :hsz_topic, :HSZ,
36
+ :h_conv_client, :HCONV,
37
+ :h_conv_server, :HCONV
38
+ end
@@ -0,0 +1,57 @@
1
+ MONCBSTRUCT Structure
2
+
3
+ --------------------------------------------------------------------------------
4
+
5
+ The MONCBSTRUCT structure contains information about the current Dynamic Data Exchange (DDE) transaction. A DDE debugging application can use this structure when monitoring transactions that the system passes to the DDE callback functions of other applications.
6
+
7
+ Syntax
8
+
9
+ typedef struct tagMONCBSTRUCT {
10
+ UINT cb;
11
+ DWORD dwTime;
12
+ HANDLE hTask;
13
+ DWORD dwRet;
14
+ UINT wType;
15
+ UINT wFmt;
16
+ HCONV hConv;
17
+ HSZ hsz1;
18
+ HSZ hsz2;
19
+ HDDEDATA hData;
20
+ ULONG_PTR dwData1;
21
+ ULONG_PTR dwData2;
22
+ CONVCONTEXT cc;
23
+ DWORD cbData;
24
+ DWORD Data[8];
25
+ } MONCBSTRUCT, *PMONCBSTRUCT;
26
+ Members
27
+
28
+ cb
29
+ Specifies the structure's size, in bytes.
30
+ dwTime
31
+ Specifies the Windows time at which the transaction occurred. Windows time is the number of milliseconds that have elapsed since the system was booted.
32
+ hTask
33
+ Handle to the task (application instance) containing the DDE callback function that received the transaction.
34
+ dwRet
35
+ Specifies the value returned by the DDE callback function that processed the transaction.
36
+ wType
37
+ Specifies the transaction type.
38
+ wFmt
39
+ Specifies the format of the data exchanged (if any) during the transaction.
40
+ hConv
41
+ Handle to the conversation in which the transaction took place.
42
+ hsz1
43
+ Handle to a string.
44
+ hsz2
45
+ Handle to a string.
46
+ hData
47
+ Handle to the data exchanged (if any) during the transaction.
48
+ dwData1
49
+ Specifies additional data.
50
+ dwData2
51
+ Specifies additional data.
52
+ cc
53
+ Specifies a CONVCONTEXT structure containing language information used to share data in different languages.
54
+ cbData
55
+ Specifies the amount, in bytes, of data being passed with the transaction. This value can be more than 32 bytes.
56
+ Data
57
+ Contains the first 32 bytes of data being passed with the transaction (8 * sizeof(DWORD)).
@@ -0,0 +1,47 @@
1
+ # MONCBSTRUCT Structure
2
+ # --------------------------------------------------------------------------------
3
+ # The MONCBSTRUCT structure contains information about the current Dynamic Data Exchange (DDE)
4
+ # transaction. A DDE debugging application can use this structure when monitoring transactions that the
5
+ # system passes to the DDE callback functions of other applications.
6
+ #
7
+ # [*Typedef*] struct { UINT cb; DWORD dwTime; HANDLE hTask; DWORD dwRet; UINT wType; UINT wFmt; HCONV
8
+ # hConv; HSZ hsz1; HSZ hsz2; HDDEDATA hData; ULONG_PTR dwData1; ULONG_PTR dwData2;
9
+ # CONVCONTEXT cc; DWORD cbData; DWORD Data[8] } MONCBSTRUCT;
10
+ #
11
+ # cb:: Specifies the structure's size, in bytes.
12
+ # dwTime:: Specifies the Windows time at which the transaction occurred. Windows time is the number of
13
+ # milliseconds that have elapsed since the system was booted.
14
+ # hTask:: Handle to the task (application instance) containing the DDE callback function that received
15
+ # the transaction.
16
+ # dwRet:: Specifies the value returned by the DDE callback function that processed the transaction.
17
+ # wType:: Specifies the transaction type.
18
+ # wFmt:: Specifies the format of the data exchanged (if any) during the transaction.
19
+ # hConv:: Handle to the conversation in which the transaction took place.
20
+ # hsz1:: Handle to a string.
21
+ # hsz2:: Handle to a string.
22
+ # hData:: Handle to the data exchanged (if any) during the transaction.
23
+ # dwData1:: Specifies additional data.
24
+ # dwData2:: Specifies additional data.
25
+ # cc:: Specifies a CONVCONTEXT structure containing language information used to share data in different
26
+ # languages.
27
+ # cbData:: Specifies the amount, in bytes, of data being passed with the transaction. This value can be
28
+ # more than 32 bytes.
29
+ # Data:: Contains the first 32 bytes of data being passed with the transaction (8 * sizeof(DWORD)).
30
+
31
+ class MONCBSTRUCT < FFI::Struct
32
+ layout :cb, :UINT,
33
+ :dw_time, :DWORD,
34
+ :h_task, :HANDLE,
35
+ :dw_ret, :DWORD,
36
+ :w_type, :UINT,
37
+ :w_fmt, :UINT,
38
+ :h_conv, :HCONV,
39
+ :hsz_1, :HSZ,
40
+ :hsz_2, :HSZ,
41
+ :h_data, :HDDEDATA,
42
+ :dw_data_1, :ULONG_PTR,
43
+ :dw_data_2, :ULONG_PTR,
44
+ :cc, :CONVCONTEXT,
45
+ :cb_data, :DWORD,
46
+ :data, [:DWORD, 8]
47
+ end
@@ -0,0 +1,2 @@
1
+ # Delegation (for autospec)
2
+ require 'my_scripts/scripts/msdn_spec'
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ require 'my_scripts/scripts/shared'
3
+
4
+ module MyScriptsTest
5
+
6
+ describe MyScripts::Msdn do
7
+ before(:each) do
8
+ @name = 'msdn'
9
+ end
10
+
11
+ context 'With explicit infile, no outfile' do
12
+
13
+ it 'reads from infile, writes to stdout' do
14
+ test_files(@name).each do |infile, outfile|
15
+ create_cli
16
+ stdout_should_receive outfile.readlines.map(&:chomp).join("\n") + "\n"
17
+ cli "#{@name} #{infile}", infile
18
+ end
19
+ end
20
+ end
21
+
22
+ it 'reads from temp file' do
23
+ text = test_files(@name)[1].first.read
24
+ temp_file = File.expand_path('/tmp/msdn_temp_file')
25
+ File.open(temp_file, 'w') do |f| f.write(text) end
26
+
27
+ lambda{@changed_text = `msdn /tmp/msdn_temp_file`}.should_not raise_error
28
+ # puts "\n\nResult: #{@changed_text}"
29
+ end
30
+
31
+ end
32
+ end
data/spec/spec_helper.rb CHANGED
@@ -23,10 +23,10 @@ module MyScriptsTest
23
23
  @cli = MyScripts::CLI.new(@stdin, @stdout, @kernel)
24
24
  end
25
25
 
26
- def cli(command_line)
26
+ def cli(command_line, argf=ARGF)
27
27
  raise "Command line should be non-empty String" unless command_line.respond_to?(:split) && command_line != ''
28
28
  argv = command_line.split(' ')
29
- @cli.run argv.shift.to_sym, argv
29
+ @cli.run argv.shift.to_sym, argv, argf
30
30
  end
31
31
 
32
32
  # Sets expectation for Kernel to receive system call with specific messages/patterns
@@ -56,4 +56,20 @@ module MyScriptsTest
56
56
  end
57
57
  end
58
58
 
59
+ # Lists files of specific type
60
+ def test_files(dir)
61
+
62
+ files_dir = Pathname(__FILE__).dirname + 'files' + dir
63
+ infiles_glob = (files_dir + '*_in.txt').to_s
64
+ outfiles_glob = (files_dir + '*_out.txt').to_s
65
+ infiles = Pathname.glob(infiles_glob)
66
+ outfiles = Pathname.glob(outfiles_glob)
67
+
68
+ if infiles.size == outfiles.size
69
+ infiles.zip(outfiles)
70
+ else
71
+ nil
72
+ end
73
+ end
74
+
59
75
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 5
9
- version: 0.1.5
8
+ - 7
9
+ version: 0.1.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - arvicco
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-17 00:00:00 +04:00
17
+ date: 2010-04-29 00:00:00 +04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -50,6 +50,7 @@ executables:
50
50
  - citi
51
51
  - gitto
52
52
  - jew
53
+ - msdn
53
54
  - rabbit
54
55
  - wake
55
56
  extensions: []
@@ -63,6 +64,7 @@ files:
63
64
  - bin/citi
64
65
  - bin/gitto
65
66
  - bin/jew
67
+ - bin/msdn
66
68
  - bin/rabbit
67
69
  - bin/wake
68
70
  - lib/my_scripts/cli.rb
@@ -72,11 +74,23 @@ files:
72
74
  - lib/my_scripts/scripts/citi.rb
73
75
  - lib/my_scripts/scripts/gitto.rb
74
76
  - lib/my_scripts/scripts/jew.rb
77
+ - lib/my_scripts/scripts/msdn/msdn_helper.rb
78
+ - lib/my_scripts/scripts/msdn.rb
75
79
  - lib/my_scripts/scripts/rabbit.rb
76
80
  - lib/my_scripts/scripts/wake.rb
77
81
  - lib/my_scripts.rb
82
+ - spec/files/msdn/ddeinit_in.txt
83
+ - spec/files/msdn/ddeinit_out.txt
84
+ - spec/files/msdn/msg_in.txt
85
+ - spec/files/msdn/msg_out.txt
86
+ - spec/files/msdn/struct1_in.txt
87
+ - spec/files/msdn/struct1_out.txt
88
+ - spec/files/msdn/struct_in.txt
89
+ - spec/files/msdn/struct_out.txt
78
90
  - spec/my_scripts/extensions_spec.rb
79
91
  - spec/my_scripts/scripts/gitto_spec.rb
92
+ - spec/my_scripts/scripts/msdn/msdn_helper_spec.rb
93
+ - spec/my_scripts/scripts/msdn_spec.rb
80
94
  - spec/my_scripts/scripts/shared.rb
81
95
  - spec/my_scripts_spec.rb
82
96
  - spec/spec.opts
@@ -132,8 +146,18 @@ signing_key:
132
146
  specification_version: 3
133
147
  summary: Describe package my_scripts
134
148
  test_files:
149
+ - spec/files/msdn/ddeinit_in.txt
150
+ - spec/files/msdn/ddeinit_out.txt
151
+ - spec/files/msdn/msg_in.txt
152
+ - spec/files/msdn/msg_out.txt
153
+ - spec/files/msdn/struct1_in.txt
154
+ - spec/files/msdn/struct1_out.txt
155
+ - spec/files/msdn/struct_in.txt
156
+ - spec/files/msdn/struct_out.txt
135
157
  - spec/my_scripts/extensions_spec.rb
136
158
  - spec/my_scripts/scripts/gitto_spec.rb
159
+ - spec/my_scripts/scripts/msdn/msdn_helper_spec.rb
160
+ - spec/my_scripts/scripts/msdn_spec.rb
137
161
  - spec/my_scripts/scripts/shared.rb
138
162
  - spec/my_scripts_spec.rb
139
163
  - spec/spec.opts