71 | | |
72 | | == Coding Questions == #coding-questions |
73 | | |
74 | | === Is the code below OK? Did I account for the terminating nulls correctly? === |
75 | | |
76 | | {{{ |
77 | | //BldFullPathName returns the fullpath of a file or Nullstr |
78 | | CHAR *FullPathName = BldFullPathName(CHAR *pathname, CHAR |
79 | | *filename) |
80 | | { |
81 | | |
82 | | CHAR newname[CCHMAXPATH] = Nullstr; |
83 | | INT c = 0; |
84 | | |
85 | | c = strlen(pathname); |
86 | | if (c > 0) { |
87 | | memcpy(newname, pathname, c + 1); |
88 | | if (newname[c] != '\\') |
89 | | newname[c++] = '\\'; |
90 | | } |
91 | | strcpy(newname + c, filename); |
92 | | return newname; |
93 | | } |
94 | | |
95 | | //BldQuotedFullPathName returns the quoted fullpath of a file or "" |
96 | | CHAR *FullPathName = BldQuotedFullPathName(CHAR *pathname, |
97 | | CHAR *filename) |
98 | | { |
99 | | |
100 | | CHAR newname[CCHMAXPATH] = '\"'; |
101 | | INT c = 0; |
102 | | |
103 | | c = strlen(pathname); |
104 | | if (c > 0) { |
105 | | memcpy(newname + 1, pathname, c + 2); |
106 | | if (newname[c + 1] != '\\') |
107 | | newname[c + 2] = '\\'; |
108 | | strcpy(newname + c + 3, filename); |
109 | | } |
110 | | else |
111 | | strcpy(newname + 1, filename) |
112 | | strcat(newname, '\"') |
113 | | return newname; |
114 | | } |
115 | | }}} |
116 | | |
117 | | Not quite. The caller must pass a pointer to the buffer. Keep in mind |
118 | | that local variable disappear when the function returns. |
119 | | |
120 | | |
121 | | {{{ |
122 | | PSZ BldFullPathName(PSZ fullPathName, PSZ dirname, PSZ filename); |
123 | | }}} |
124 | | |
125 | | |
126 | | |
127 | | {{{ |
128 | | CHAR newname[CCHMAXPATH] = Nullstr; |
129 | | }}} |
130 | | |
131 | | |
132 | | This will give you an error because NullStr is a pointer. |
133 | | |
134 | | |
135 | | {{{ |
136 | | CHAR newname[CCHMAXPATH]; |
137 | | }}} |
138 | | |
139 | | |
140 | | Is sufficent since you are always going to copy something. The return is |
141 | | |
142 | | |
143 | | {{{ |
144 | | return fullPathName |
145 | | }}} |
146 | | |
147 | | |
148 | | with the appropriate name changes. |
149 | | |
150 | | |
151 | | {{{ |
152 | | //BldQuotedFullPathName returns the quoted fullpath of a file or "" CHAR |
153 | | }}} |
154 | | |
155 | | |
156 | | The quotes need to be optional and the return buffer needs to be passed as |
157 | | above. |
158 | | |
159 | | |
160 | | {{{ |
161 | | PSZ BldQuotedFullPathName(PSZ fullPathName, PSZ pathname, PSZ filename) |
162 | | }}} |
163 | | |
164 | | |
165 | | You also need to add the calls to needs_quotes() a stuff the quotes only |
166 | | if needed. This is what the existing inline code does. |
167 | | |
168 | | === What is the purpose of quoting functions? === |
169 | | |
170 | | Its purpose is to replace repeated occurances of code of the form |
171 | | |
172 | | |
173 | | {{{ |
174 | | sprintf(cl, "%s %s%s%s", dcd->info->delete, |
175 | | (needs_quoting(dcd->arcname)) ? "\"" : NullStr, |
176 | | dcd->arcname, |
177 | | (needs_quoting(dcd->arcname)) ? "\"" : NullStr); |
178 | | }}} |
179 | | |
180 | | |
181 | | and possibly |
182 | | |
183 | | |
184 | | {{{ |
185 | | runemf2(SEPARATEKEEP | WINDOWED | MAXIMIZED, |
186 | | hwnd, NULL, NULL, "%s %s%s%s", ad->info->test, |
187 | | needs_quoting(ad->arcname) ? "\"" : NullStr, |
188 | | ad->arcname, |
189 | | needs_quoting(ad->arcname) ? "\"" : NullStr); |
190 | | }}} |
191 | | |
192 | | |
193 | | === Where is the best place to do a check for? === |
194 | | |
195 | | Since the check always needs to be done, it's generally better to do it in |
196 | | the function. |
197 | | |
| 101 | |
| 102 | == Coding Questions == #coding-questions |
| 103 | |
| 104 | === Is the code below OK? Did I account for the terminating nulls correctly? === |
| 105 | |
| 106 | {{{ |
| 107 | //BldFullPathName returns the fullpath of a file or Nullstr |
| 108 | CHAR *FullPathName = BldFullPathName(CHAR *pathname, CHAR |
| 109 | *filename) |
| 110 | { |
| 111 | |
| 112 | CHAR newname[CCHMAXPATH] = Nullstr; |
| 113 | INT c = 0; |
| 114 | |
| 115 | c = strlen(pathname); |
| 116 | if (c > 0) { |
| 117 | memcpy(newname, pathname, c + 1); |
| 118 | if (newname[c] != '\\') |
| 119 | newname[c++] = '\\'; |
| 120 | } |
| 121 | strcpy(newname + c, filename); |
| 122 | return newname; |
| 123 | } |
| 124 | |
| 125 | //BldQuotedFullPathName returns the quoted fullpath of a file or "" |
| 126 | CHAR *FullPathName = BldQuotedFullPathName(CHAR *pathname, |
| 127 | CHAR *filename) |
| 128 | { |
| 129 | |
| 130 | CHAR newname[CCHMAXPATH] = '\"'; |
| 131 | INT c = 0; |
| 132 | |
| 133 | c = strlen(pathname); |
| 134 | if (c > 0) { |
| 135 | memcpy(newname + 1, pathname, c + 2); |
| 136 | if (newname[c + 1] != '\\') |
| 137 | newname[c + 2] = '\\'; |
| 138 | strcpy(newname + c + 3, filename); |
| 139 | } |
| 140 | else |
| 141 | strcpy(newname + 1, filename) |
| 142 | strcat(newname, '\"') |
| 143 | return newname; |
| 144 | } |
| 145 | }}} |
| 146 | |
| 147 | Not quite. The caller must pass a pointer to the buffer. Keep in mind |
| 148 | that local variable disappear when the function returns. |
| 149 | |
| 150 | |
| 151 | {{{ |
| 152 | PSZ BldFullPathName(PSZ fullPathName, PSZ dirname, PSZ filename); |
| 153 | }}} |
| 154 | |
| 155 | |
| 156 | |
| 157 | {{{ |
| 158 | CHAR newname[CCHMAXPATH] = Nullstr; |
| 159 | }}} |
| 160 | |
| 161 | |
| 162 | This will give you an error because NullStr is a pointer. |
| 163 | |
| 164 | |
| 165 | {{{ |
| 166 | CHAR newname[CCHMAXPATH]; |
| 167 | }}} |
| 168 | |
| 169 | |
| 170 | Is sufficent since you are always going to copy something. The return is |
| 171 | |
| 172 | |
| 173 | {{{ |
| 174 | return fullPathName |
| 175 | }}} |
| 176 | |
| 177 | |
| 178 | with the appropriate name changes. |
| 179 | |
| 180 | |
| 181 | {{{ |
| 182 | //BldQuotedFullPathName returns the quoted fullpath of a file or "" CHAR |
| 183 | }}} |
| 184 | |
| 185 | |
| 186 | The quotes need to be optional and the return buffer needs to be passed as |
| 187 | above. |
| 188 | |
| 189 | |
| 190 | {{{ |
| 191 | PSZ BldQuotedFullPathName(PSZ fullPathName, PSZ pathname, PSZ filename) |
| 192 | }}} |
| 193 | |
| 194 | |
| 195 | You also need to add the calls to needs_quotes() a stuff the quotes only |
| 196 | if needed. This is what the existing inline code does. |
| 197 | |
| 198 | === What is the purpose of quoting functions? === |
| 199 | |
| 200 | Its purpose is to replace repeated occurances of code of the form |
| 201 | |
| 202 | |
| 203 | {{{ |
| 204 | sprintf(cl, "%s %s%s%s", dcd->info->delete, |
| 205 | (needs_quoting(dcd->arcname)) ? "\"" : NullStr, |
| 206 | dcd->arcname, |
| 207 | (needs_quoting(dcd->arcname)) ? "\"" : NullStr); |
| 208 | }}} |
| 209 | |
| 210 | |
| 211 | and possibly |
| 212 | |
| 213 | |
| 214 | {{{ |
| 215 | runemf2(SEPARATEKEEP | WINDOWED | MAXIMIZED, |
| 216 | hwnd, NULL, NULL, "%s %s%s%s", ad->info->test, |
| 217 | needs_quoting(ad->arcname) ? "\"" : NullStr, |
| 218 | ad->arcname, |
| 219 | needs_quoting(ad->arcname) ? "\"" : NullStr); |
| 220 | }}} |
| 221 | |
| 222 | |
| 223 | === Where is the best place to do a check for? === |
| 224 | |
| 225 | Since the check always needs to be done, it's generally better to do it in |
| 226 | the function. |
| 227 | |
| 228 | |
| 229 | ---- |