@mytechtoday/augment-extensions 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (307) hide show
  1. package/augment-extensions/coding-standards/c/CHANGELOG.md +55 -0
  2. package/augment-extensions/coding-standards/c/LICENSE +22 -0
  3. package/augment-extensions/coding-standards/c/README.md +167 -0
  4. package/augment-extensions/coding-standards/c/config/defaults.json +26 -0
  5. package/augment-extensions/coding-standards/c/config/examples/embedded.yaml +25 -0
  6. package/augment-extensions/coding-standards/c/config/examples/systems.json +31 -0
  7. package/augment-extensions/coding-standards/c/config/schema.json +244 -0
  8. package/augment-extensions/coding-standards/c/docs/API.md +613 -0
  9. package/augment-extensions/coding-standards/c/docs/CONFIGURATION.md +259 -0
  10. package/augment-extensions/coding-standards/c/docs/USER_GUIDE.md +567 -0
  11. package/augment-extensions/coding-standards/c/examples/drivers/Makefile +33 -0
  12. package/augment-extensions/coding-standards/c/examples/drivers/README.md +192 -0
  13. package/augment-extensions/coding-standards/c/examples/drivers/dma-example.c +224 -0
  14. package/augment-extensions/coding-standards/c/examples/drivers/example.dts +64 -0
  15. package/augment-extensions/coding-standards/c/examples/drivers/platform-driver.c +174 -0
  16. package/augment-extensions/coding-standards/c/examples/embedded/README.md +167 -0
  17. package/augment-extensions/coding-standards/c/examples/embedded/gpio-control.c +172 -0
  18. package/augment-extensions/coding-standards/c/examples/embedded/timer-isr.c +198 -0
  19. package/augment-extensions/coding-standards/c/examples/embedded/uart-communication.c +212 -0
  20. package/augment-extensions/coding-standards/c/examples/kernel/Makefile +82 -0
  21. package/augment-extensions/coding-standards/c/examples/kernel/README.md +168 -0
  22. package/augment-extensions/coding-standards/c/examples/kernel/char-device.c +198 -0
  23. package/augment-extensions/coding-standards/c/examples/kernel/proc-file.c +131 -0
  24. package/augment-extensions/coding-standards/c/examples/kernel/simple-module.c +111 -0
  25. package/augment-extensions/coding-standards/c/examples/legacy/Makefile +62 -0
  26. package/augment-extensions/coding-standards/c/examples/legacy/README.md +255 -0
  27. package/augment-extensions/coding-standards/c/examples/legacy/c89-to-c11-migration.c +268 -0
  28. package/augment-extensions/coding-standards/c/examples/legacy/compatibility-layer.c +239 -0
  29. package/augment-extensions/coding-standards/c/examples/networking/Makefile +35 -0
  30. package/augment-extensions/coding-standards/c/examples/networking/README.md +207 -0
  31. package/augment-extensions/coding-standards/c/examples/networking/protocol-parser.c +270 -0
  32. package/augment-extensions/coding-standards/c/examples/networking/tcp-server.c +197 -0
  33. package/augment-extensions/coding-standards/c/examples/networking/udp-multicast.c +220 -0
  34. package/augment-extensions/coding-standards/c/examples/realtime/Makefile +53 -0
  35. package/augment-extensions/coding-standards/c/examples/realtime/README.md +199 -0
  36. package/augment-extensions/coding-standards/c/examples/realtime/deadline-monitoring.c +260 -0
  37. package/augment-extensions/coding-standards/c/examples/realtime/priority-scheduling.c +258 -0
  38. package/augment-extensions/coding-standards/c/examples/systems/Makefile +34 -0
  39. package/augment-extensions/coding-standards/c/examples/systems/README.md +123 -0
  40. package/augment-extensions/coding-standards/c/examples/systems/ipc-pipes.c +181 -0
  41. package/augment-extensions/coding-standards/c/examples/systems/process-management.c +153 -0
  42. package/augment-extensions/coding-standards/c/examples/systems/signal-handling.c +162 -0
  43. package/augment-extensions/coding-standards/c/module.json +149 -0
  44. package/augment-extensions/coding-standards/c/rules/categories/drivers.md +635 -0
  45. package/augment-extensions/coding-standards/c/rules/categories/embedded.md +510 -0
  46. package/augment-extensions/coding-standards/c/rules/categories/kernel.md +653 -0
  47. package/augment-extensions/coding-standards/c/rules/categories/legacy.md +526 -0
  48. package/augment-extensions/coding-standards/c/rules/categories/networking.md +735 -0
  49. package/augment-extensions/coding-standards/c/rules/categories/realtime.md +631 -0
  50. package/augment-extensions/coding-standards/c/rules/categories/systems.md +586 -0
  51. package/augment-extensions/coding-standards/c/rules/universal/const-correctness.md +275 -0
  52. package/augment-extensions/coding-standards/c/rules/universal/documentation.md +251 -0
  53. package/augment-extensions/coding-standards/c/rules/universal/error-handling.md +250 -0
  54. package/augment-extensions/coding-standards/c/rules/universal/header-guards.md +254 -0
  55. package/augment-extensions/coding-standards/c/rules/universal/memory-safety.md +233 -0
  56. package/augment-extensions/coding-standards/c/rules/universal/naming.md +146 -0
  57. package/augment-extensions/coding-standards/c/src/conflict-detector.ts +461 -0
  58. package/augment-extensions/coding-standards/c/src/prompt-generator.ts +307 -0
  59. package/augment-extensions/coding-standards/c/src/rule-evaluator.ts +307 -0
  60. package/augment-extensions/coding-standards/c/src/rule-override.ts +427 -0
  61. package/augment-extensions/coding-standards/c/src/template-engine.ts +217 -0
  62. package/augment-extensions/coding-standards/c/templates/prompts/drivers.txt +191 -0
  63. package/augment-extensions/coding-standards/c/templates/prompts/embedded.txt +164 -0
  64. package/augment-extensions/coding-standards/c/templates/prompts/kernel.txt +175 -0
  65. package/augment-extensions/coding-standards/c/templates/prompts/legacy.txt +280 -0
  66. package/augment-extensions/coding-standards/c/templates/prompts/networking.txt +259 -0
  67. package/augment-extensions/coding-standards/c/templates/prompts/realtime.txt +219 -0
  68. package/augment-extensions/coding-standards/c/templates/prompts/systems.txt +147 -0
  69. package/augment-extensions/coding-standards/c/tests/integration/category-specific.test.ts +356 -0
  70. package/augment-extensions/coding-standards/c/tests/integration/end-to-end-workflow.test.ts +377 -0
  71. package/augment-extensions/coding-standards/c/tests/performance/benchmarks.test.ts +407 -0
  72. package/augment-extensions/coding-standards/c/tests/unit/config-manager.test.ts +345 -0
  73. package/augment-extensions/coding-standards/c/tests/unit/conflict-detector.test.ts +294 -0
  74. package/augment-extensions/coding-standards/c/tests/unit/prompt-generator.test.ts +174 -0
  75. package/augment-extensions/coding-standards/c/tests/unit/registry.test.ts +313 -0
  76. package/augment-extensions/coding-standards/c/tests/unit/rule-evaluator.test.ts +318 -0
  77. package/augment-extensions/coding-standards/c/tests/unit/rule-override.test.ts +326 -0
  78. package/augment-extensions/coding-standards/c/tests/unit/template-engine.test.ts +314 -0
  79. package/augment-extensions/coding-standards/go/CHARACTER-COUNT-REPORT.md +135 -0
  80. package/augment-extensions/coding-standards/go/PHASE1-COMPLETION.md +146 -0
  81. package/augment-extensions/coding-standards/go/PHASE4-COMPLETION.md +184 -0
  82. package/augment-extensions/coding-standards/go/README.md +200 -0
  83. package/augment-extensions/coding-standards/go/VALIDATION-CHECKLIST.md +154 -0
  84. package/augment-extensions/coding-standards/go/config/examples/example-cli.json +15 -0
  85. package/augment-extensions/coding-standards/go/config/examples/example-microservices.json +21 -0
  86. package/augment-extensions/coding-standards/go/config/examples/example-multi-category.yaml +24 -0
  87. package/augment-extensions/coding-standards/go/config/examples/example-web.json +15 -0
  88. package/augment-extensions/coding-standards/go/config/schema.json +110 -0
  89. package/augment-extensions/coding-standards/go/docs/CATEGORIES.md +221 -0
  90. package/augment-extensions/coding-standards/go/docs/CONFIGURATION.md +198 -0
  91. package/augment-extensions/coding-standards/go/docs/TROUBLESHOOTING.md +285 -0
  92. package/augment-extensions/coding-standards/go/examples/cli/cobra-app.go +287 -0
  93. package/augment-extensions/coding-standards/go/examples/cloud-native-app.go +217 -0
  94. package/augment-extensions/coding-standards/go/examples/devops-tool.go +250 -0
  95. package/augment-extensions/coding-standards/go/examples/distributed-system.go +247 -0
  96. package/augment-extensions/coding-standards/go/examples/microservices/grpc-service.go +253 -0
  97. package/augment-extensions/coding-standards/go/examples/rest-api.go +270 -0
  98. package/augment-extensions/coding-standards/go/examples/web/http-server.go +224 -0
  99. package/augment-extensions/coding-standards/go/module.json +139 -0
  100. package/augment-extensions/coding-standards/go/rules/categories/api-development/api-versioning.md +149 -0
  101. package/augment-extensions/coding-standards/go/rules/categories/api-development/rate-limiting.md +209 -0
  102. package/augment-extensions/coding-standards/go/rules/categories/api-development/rest-api-design.md +183 -0
  103. package/augment-extensions/coding-standards/go/rules/categories/cloud-native/cloud-config.md +193 -0
  104. package/augment-extensions/coding-standards/go/rules/categories/cloud-native/health-checks.md +231 -0
  105. package/augment-extensions/coding-standards/go/rules/categories/cloud-native/kubernetes.md +180 -0
  106. package/augment-extensions/coding-standards/go/rules/categories/devops-tooling/automation.md +179 -0
  107. package/augment-extensions/coding-standards/go/rules/categories/devops-tooling/ci-cd-integration.md +147 -0
  108. package/augment-extensions/coding-standards/go/rules/categories/devops-tooling/infrastructure-as-code.md +231 -0
  109. package/augment-extensions/coding-standards/go/rules/categories/distributed-systems/caching.md +150 -0
  110. package/augment-extensions/coding-standards/go/rules/categories/distributed-systems/consensus.md +187 -0
  111. package/augment-extensions/coding-standards/go/rules/categories/distributed-systems/event-sourcing.md +246 -0
  112. package/augment-extensions/coding-standards/go/rules/cli/command-parsing.md +264 -0
  113. package/augment-extensions/coding-standards/go/rules/cli/configuration.md +268 -0
  114. package/augment-extensions/coding-standards/go/rules/cli/cross-platform.md +324 -0
  115. package/augment-extensions/coding-standards/go/rules/microservices/distributed-tracing.md +253 -0
  116. package/augment-extensions/coding-standards/go/rules/microservices/grpc.md +257 -0
  117. package/augment-extensions/coding-standards/go/rules/microservices/metrics.md +278 -0
  118. package/augment-extensions/coding-standards/go/rules/microservices/service-discovery.md +249 -0
  119. package/augment-extensions/coding-standards/go/rules/universal/code-organization.md +221 -0
  120. package/augment-extensions/coding-standards/go/rules/universal/documentation.md +269 -0
  121. package/augment-extensions/coding-standards/go/rules/universal/performance.md +323 -0
  122. package/augment-extensions/coding-standards/go/rules/universal/testing.md +162 -0
  123. package/augment-extensions/coding-standards/go/rules/web/graceful-shutdown.md +249 -0
  124. package/augment-extensions/coding-standards/go/rules/web/http-handlers.md +164 -0
  125. package/augment-extensions/coding-standards/go/rules/web/middleware.md +234 -0
  126. package/augment-extensions/coding-standards/go/rules/web/routing.md +251 -0
  127. package/augment-extensions/coding-standards/go/templates/prompts/api.md +160 -0
  128. package/augment-extensions/coding-standards/go/templates/prompts/cli.md +225 -0
  129. package/augment-extensions/coding-standards/go/templates/prompts/cloud-native.md +121 -0
  130. package/augment-extensions/coding-standards/go/templates/prompts/devops.md +146 -0
  131. package/augment-extensions/coding-standards/go/templates/prompts/distributed.md +133 -0
  132. package/augment-extensions/coding-standards/go/templates/prompts/microservices.md +225 -0
  133. package/augment-extensions/coding-standards/go/templates/prompts/web.md +181 -0
  134. package/augment-extensions/coding-standards/go/tests/integration/module-integration.test.ts +164 -0
  135. package/augment-extensions/coding-standards/go/tests/unit/category-selection.test.ts +147 -0
  136. package/augment-extensions/coding-standards/go/tests/unit/module-structure.test.ts +154 -0
  137. package/augment-extensions/coding-standards/go/tests/validate-character-count.ps1 +13 -0
  138. package/augment-extensions/coding-standards/go/tests/validate-examples.ps1 +148 -0
  139. package/augment-extensions/coding-standards/go/tests/validate-examples.sh +135 -0
  140. package/cli/dist/analysis/ast-parser.d.ts +47 -0
  141. package/cli/dist/analysis/ast-parser.d.ts.map +1 -0
  142. package/cli/dist/analysis/ast-parser.js +161 -0
  143. package/cli/dist/analysis/ast-parser.js.map +1 -0
  144. package/cli/dist/analysis/complexity-analyzer.d.ts +27 -0
  145. package/cli/dist/analysis/complexity-analyzer.d.ts.map +1 -0
  146. package/cli/dist/analysis/complexity-analyzer.js +189 -0
  147. package/cli/dist/analysis/complexity-analyzer.js.map +1 -0
  148. package/cli/dist/analysis/dependency-analyzer.d.ts +23 -0
  149. package/cli/dist/analysis/dependency-analyzer.d.ts.map +1 -0
  150. package/cli/dist/analysis/dependency-analyzer.js +237 -0
  151. package/cli/dist/analysis/dependency-analyzer.js.map +1 -0
  152. package/cli/dist/analysis/index.d.ts +9 -0
  153. package/cli/dist/analysis/index.d.ts.map +1 -0
  154. package/cli/dist/analysis/index.js +25 -0
  155. package/cli/dist/analysis/index.js.map +1 -0
  156. package/cli/dist/analysis/security-scanner.d.ts +11 -0
  157. package/cli/dist/analysis/security-scanner.d.ts.map +1 -0
  158. package/cli/dist/analysis/security-scanner.js +294 -0
  159. package/cli/dist/analysis/security-scanner.js.map +1 -0
  160. package/cli/dist/analysis/types.d.ts +151 -0
  161. package/cli/dist/analysis/types.d.ts.map +1 -0
  162. package/cli/dist/analysis/types.js +6 -0
  163. package/cli/dist/analysis/types.js.map +1 -0
  164. package/cli/dist/cli.js +24 -0
  165. package/cli/dist/cli.js.map +1 -1
  166. package/cli/dist/commands/code-analysis.d.ts +11 -0
  167. package/cli/dist/commands/code-analysis.d.ts.map +1 -0
  168. package/cli/dist/commands/code-analysis.js +412 -0
  169. package/cli/dist/commands/code-analysis.js.map +1 -0
  170. package/modules.md +99 -3
  171. package/package.json +14 -2
  172. package/cli/dist/commands/agent.d.ts +0 -37
  173. package/cli/dist/commands/agent.d.ts.map +0 -1
  174. package/cli/dist/commands/agent.js +0 -222
  175. package/cli/dist/commands/agent.js.map +0 -1
  176. package/cli/dist/commands/beads.d.ts +0 -64
  177. package/cli/dist/commands/beads.d.ts.map +0 -1
  178. package/cli/dist/commands/beads.js +0 -377
  179. package/cli/dist/commands/beads.js.map +0 -1
  180. package/cli/dist/commands/change.d.ts +0 -54
  181. package/cli/dist/commands/change.d.ts.map +0 -1
  182. package/cli/dist/commands/change.js +0 -243
  183. package/cli/dist/commands/change.js.map +0 -1
  184. package/cli/dist/commands/clean.d.ts +0 -15
  185. package/cli/dist/commands/clean.d.ts.map +0 -1
  186. package/cli/dist/commands/clean.js +0 -63
  187. package/cli/dist/commands/clean.js.map +0 -1
  188. package/cli/dist/commands/clone.d.ts +0 -15
  189. package/cli/dist/commands/clone.d.ts.map +0 -1
  190. package/cli/dist/commands/clone.js +0 -49
  191. package/cli/dist/commands/clone.js.map +0 -1
  192. package/cli/dist/commands/config.d.ts +0 -33
  193. package/cli/dist/commands/config.d.ts.map +0 -1
  194. package/cli/dist/commands/config.js +0 -166
  195. package/cli/dist/commands/config.js.map +0 -1
  196. package/cli/dist/commands/context.d.ts +0 -38
  197. package/cli/dist/commands/context.d.ts.map +0 -1
  198. package/cli/dist/commands/context.js +0 -205
  199. package/cli/dist/commands/context.js.map +0 -1
  200. package/cli/dist/commands/create.d.ts +0 -18
  201. package/cli/dist/commands/create.d.ts.map +0 -1
  202. package/cli/dist/commands/create.js +0 -178
  203. package/cli/dist/commands/create.js.map +0 -1
  204. package/cli/dist/commands/diff.d.ts +0 -19
  205. package/cli/dist/commands/diff.d.ts.map +0 -1
  206. package/cli/dist/commands/diff.js +0 -104
  207. package/cli/dist/commands/diff.js.map +0 -1
  208. package/cli/dist/commands/doctor.d.ts +0 -14
  209. package/cli/dist/commands/doctor.d.ts.map +0 -1
  210. package/cli/dist/commands/doctor.js +0 -62
  211. package/cli/dist/commands/doctor.js.map +0 -1
  212. package/cli/dist/commands/export.d.ts +0 -28
  213. package/cli/dist/commands/export.d.ts.map +0 -1
  214. package/cli/dist/commands/export.js +0 -135
  215. package/cli/dist/commands/export.js.map +0 -1
  216. package/cli/dist/commands/import.d.ts +0 -23
  217. package/cli/dist/commands/import.d.ts.map +0 -1
  218. package/cli/dist/commands/import.js +0 -118
  219. package/cli/dist/commands/import.js.map +0 -1
  220. package/cli/dist/commands/prompt.d.ts +0 -45
  221. package/cli/dist/commands/prompt.d.ts.map +0 -1
  222. package/cli/dist/commands/prompt.js +0 -223
  223. package/cli/dist/commands/prompt.js.map +0 -1
  224. package/cli/dist/commands/spec.d.ts +0 -57
  225. package/cli/dist/commands/spec.d.ts.map +0 -1
  226. package/cli/dist/commands/spec.js +0 -279
  227. package/cli/dist/commands/spec.js.map +0 -1
  228. package/cli/dist/commands/stats.d.ts +0 -18
  229. package/cli/dist/commands/stats.d.ts.map +0 -1
  230. package/cli/dist/commands/stats.js +0 -85
  231. package/cli/dist/commands/stats.js.map +0 -1
  232. package/cli/dist/commands/task.d.ts +0 -65
  233. package/cli/dist/commands/task.d.ts.map +0 -1
  234. package/cli/dist/commands/task.js +0 -282
  235. package/cli/dist/commands/task.js.map +0 -1
  236. package/cli/dist/commands/template.d.ts +0 -17
  237. package/cli/dist/commands/template.d.ts.map +0 -1
  238. package/cli/dist/commands/template.js +0 -55
  239. package/cli/dist/commands/template.js.map +0 -1
  240. package/cli/dist/utils/agent-config.d.ts +0 -129
  241. package/cli/dist/utils/agent-config.d.ts.map +0 -1
  242. package/cli/dist/utils/agent-config.js +0 -297
  243. package/cli/dist/utils/agent-config.js.map +0 -1
  244. package/cli/dist/utils/beads-graph.d.ts +0 -17
  245. package/cli/dist/utils/beads-graph.d.ts.map +0 -1
  246. package/cli/dist/utils/beads-graph.js +0 -150
  247. package/cli/dist/utils/beads-graph.js.map +0 -1
  248. package/cli/dist/utils/beads-integration.d.ts +0 -112
  249. package/cli/dist/utils/beads-integration.d.ts.map +0 -1
  250. package/cli/dist/utils/beads-integration.js +0 -312
  251. package/cli/dist/utils/beads-integration.js.map +0 -1
  252. package/cli/dist/utils/beads-reporter.d.ts +0 -17
  253. package/cli/dist/utils/beads-reporter.d.ts.map +0 -1
  254. package/cli/dist/utils/beads-reporter.js +0 -160
  255. package/cli/dist/utils/beads-reporter.js.map +0 -1
  256. package/cli/dist/utils/cache-manager.d.ts +0 -55
  257. package/cli/dist/utils/cache-manager.d.ts.map +0 -1
  258. package/cli/dist/utils/cache-manager.js +0 -150
  259. package/cli/dist/utils/cache-manager.js.map +0 -1
  260. package/cli/dist/utils/change-manager.d.ts +0 -70
  261. package/cli/dist/utils/change-manager.d.ts.map +0 -1
  262. package/cli/dist/utils/change-manager.js +0 -412
  263. package/cli/dist/utils/change-manager.js.map +0 -1
  264. package/cli/dist/utils/config-manager-enhanced.d.ts +0 -66
  265. package/cli/dist/utils/config-manager-enhanced.d.ts.map +0 -1
  266. package/cli/dist/utils/config-manager-enhanced.js +0 -77
  267. package/cli/dist/utils/config-manager-enhanced.js.map +0 -1
  268. package/cli/dist/utils/context-manager.d.ts +0 -96
  269. package/cli/dist/utils/context-manager.d.ts.map +0 -1
  270. package/cli/dist/utils/context-manager.js +0 -258
  271. package/cli/dist/utils/context-manager.js.map +0 -1
  272. package/cli/dist/utils/diff-engine.d.ts +0 -78
  273. package/cli/dist/utils/diff-engine.d.ts.map +0 -1
  274. package/cli/dist/utils/diff-engine.js +0 -233
  275. package/cli/dist/utils/diff-engine.js.map +0 -1
  276. package/cli/dist/utils/export-system.d.ts +0 -101
  277. package/cli/dist/utils/export-system.d.ts.map +0 -1
  278. package/cli/dist/utils/export-system.js +0 -289
  279. package/cli/dist/utils/export-system.js.map +0 -1
  280. package/cli/dist/utils/health-checker.d.ts +0 -66
  281. package/cli/dist/utils/health-checker.d.ts.map +0 -1
  282. package/cli/dist/utils/health-checker.js +0 -285
  283. package/cli/dist/utils/health-checker.js.map +0 -1
  284. package/cli/dist/utils/import-system.d.ts +0 -74
  285. package/cli/dist/utils/import-system.d.ts.map +0 -1
  286. package/cli/dist/utils/import-system.js +0 -317
  287. package/cli/dist/utils/import-system.js.map +0 -1
  288. package/cli/dist/utils/module-cloner.d.ts +0 -40
  289. package/cli/dist/utils/module-cloner.d.ts.map +0 -1
  290. package/cli/dist/utils/module-cloner.js +0 -136
  291. package/cli/dist/utils/module-cloner.js.map +0 -1
  292. package/cli/dist/utils/prompt-manager.d.ts +0 -90
  293. package/cli/dist/utils/prompt-manager.d.ts.map +0 -1
  294. package/cli/dist/utils/prompt-manager.js +0 -302
  295. package/cli/dist/utils/prompt-manager.js.map +0 -1
  296. package/cli/dist/utils/spec-manager.d.ts +0 -65
  297. package/cli/dist/utils/spec-manager.d.ts.map +0 -1
  298. package/cli/dist/utils/spec-manager.js +0 -329
  299. package/cli/dist/utils/spec-manager.js.map +0 -1
  300. package/cli/dist/utils/stats-collector.d.ts +0 -74
  301. package/cli/dist/utils/stats-collector.d.ts.map +0 -1
  302. package/cli/dist/utils/stats-collector.js +0 -164
  303. package/cli/dist/utils/stats-collector.js.map +0 -1
  304. package/cli/dist/utils/template-engine.d.ts +0 -47
  305. package/cli/dist/utils/template-engine.d.ts.map +0 -1
  306. package/cli/dist/utils/template-engine.js +0 -204
  307. package/cli/dist/utils/template-engine.js.map +0 -1
@@ -0,0 +1,131 @@
1
+ /**
2
+ * @file proc-file.c
3
+ * @brief Example Linux kernel /proc filesystem interface
4
+ *
5
+ * This example demonstrates:
6
+ * - Creating /proc entries
7
+ * - Read/write operations in /proc
8
+ * - Kernel-user space data transfer
9
+ * - Sequence file interface
10
+ *
11
+ * Build: make
12
+ * Load: sudo insmod proc-file.ko
13
+ * Test: cat /proc/example_proc
14
+ * echo "value" > /proc/example_proc
15
+ * Unload: sudo rmmod proc-file
16
+ */
17
+
18
+ #include <linux/module.h>
19
+ #include <linux/kernel.h>
20
+ #include <linux/proc_fs.h>
21
+ #include <linux/seq_file.h>
22
+ #include <linux/uaccess.h>
23
+ #include <linux/slab.h>
24
+
25
+ #define PROC_NAME "example_proc"
26
+ #define BUFFER_SIZE 256
27
+
28
+ MODULE_LICENSE("GPL");
29
+ MODULE_AUTHOR("Example Author");
30
+ MODULE_DESCRIPTION("Example /proc file interface");
31
+ MODULE_VERSION("1.0");
32
+
33
+ static struct proc_dir_entry *proc_entry = NULL;
34
+ static char *proc_buffer = NULL;
35
+ static size_t proc_buffer_size = 0;
36
+
37
+ /**
38
+ * @brief Show function for seq_file
39
+ */
40
+ static int proc_show(struct seq_file *m, void *v) {
41
+ if (proc_buffer_size > 0) {
42
+ seq_printf(m, "Stored data: %s\n", proc_buffer);
43
+ seq_printf(m, "Buffer size: %zu bytes\n", proc_buffer_size);
44
+ } else {
45
+ seq_printf(m, "No data stored\n");
46
+ }
47
+
48
+ seq_printf(m, "Module loaded at: %s %s\n", __DATE__, __TIME__);
49
+ return 0;
50
+ }
51
+
52
+ /**
53
+ * @brief Open function for proc file
54
+ */
55
+ static int proc_open(struct inode *inode, struct file *file) {
56
+ return single_open(file, proc_show, NULL);
57
+ }
58
+
59
+ /**
60
+ * @brief Write function for proc file
61
+ */
62
+ static ssize_t proc_write(struct file *file, const char __user *user_buffer,
63
+ size_t count, loff_t *offset) {
64
+ size_t to_copy;
65
+
66
+ if (count > BUFFER_SIZE - 1) {
67
+ pr_warn("proc_file: Input too large, truncating\n");
68
+ to_copy = BUFFER_SIZE - 1;
69
+ } else {
70
+ to_copy = count;
71
+ }
72
+
73
+ if (copy_from_user(proc_buffer, user_buffer, to_copy)) {
74
+ return -EFAULT;
75
+ }
76
+
77
+ proc_buffer[to_copy] = '\0'; // Null-terminate
78
+ proc_buffer_size = to_copy;
79
+
80
+ pr_info("proc_file: Received %zu bytes\n", to_copy);
81
+ return to_copy;
82
+ }
83
+
84
+ // File operations for proc file
85
+ static const struct proc_ops proc_fops = {
86
+ .proc_open = proc_open,
87
+ .proc_read = seq_read,
88
+ .proc_write = proc_write,
89
+ .proc_lseek = seq_lseek,
90
+ .proc_release = single_release,
91
+ };
92
+
93
+ /**
94
+ * @brief Module initialization
95
+ */
96
+ static int __init proc_file_init(void) {
97
+ pr_info("proc_file: Initializing module\n");
98
+
99
+ // Allocate buffer
100
+ proc_buffer = kmalloc(BUFFER_SIZE, GFP_KERNEL);
101
+ if (!proc_buffer) {
102
+ pr_err("proc_file: Failed to allocate buffer\n");
103
+ return -ENOMEM;
104
+ }
105
+
106
+ memset(proc_buffer, 0, BUFFER_SIZE);
107
+
108
+ // Create proc entry
109
+ proc_entry = proc_create(PROC_NAME, 0666, NULL, &proc_fops);
110
+ if (!proc_entry) {
111
+ pr_err("proc_file: Failed to create /proc/%s\n", PROC_NAME);
112
+ kfree(proc_buffer);
113
+ return -ENOMEM;
114
+ }
115
+
116
+ pr_info("proc_file: Created /proc/%s\n", PROC_NAME);
117
+ return 0;
118
+ }
119
+
120
+ /**
121
+ * @brief Module cleanup
122
+ */
123
+ static void __exit proc_file_exit(void) {
124
+ proc_remove(proc_entry);
125
+ kfree(proc_buffer);
126
+ pr_info("proc_file: Module unloaded\n");
127
+ }
128
+
129
+ module_init(proc_file_init);
130
+ module_exit(proc_file_exit);
131
+
@@ -0,0 +1,111 @@
1
+ /**
2
+ * @file simple-module.c
3
+ * @brief Example Linux kernel module demonstrating basic module structure
4
+ *
5
+ * This example demonstrates:
6
+ * - Module initialization and cleanup
7
+ * - Module parameters
8
+ * - Kernel logging (printk)
9
+ * - Module metadata
10
+ * - Error handling in init
11
+ *
12
+ * Build: make
13
+ * Load: sudo insmod simple-module.ko
14
+ * Load with param: sudo insmod simple-module.ko debug_level=2
15
+ * Check logs: dmesg | tail
16
+ * Unload: sudo rmmod simple-module
17
+ */
18
+
19
+ #include <linux/module.h>
20
+ #include <linux/kernel.h>
21
+ #include <linux/init.h>
22
+ #include <linux/slab.h>
23
+
24
+ MODULE_LICENSE("GPL");
25
+ MODULE_AUTHOR("Example Author <author@example.com>");
26
+ MODULE_DESCRIPTION("Simple example kernel module");
27
+ MODULE_VERSION("1.0");
28
+
29
+ // Module parameters
30
+ static int debug_level = 0;
31
+ module_param(debug_level, int, 0644);
32
+ MODULE_PARM_DESC(debug_level, "Debug level (0=off, 1=info, 2=verbose)");
33
+
34
+ static char *message = "Hello";
35
+ module_param(message, charp, 0644);
36
+ MODULE_PARM_DESC(message, "Custom message to display");
37
+
38
+ // Module data
39
+ static void *module_data = NULL;
40
+
41
+ /**
42
+ * @brief Helper function to demonstrate kernel logging
43
+ */
44
+ static void log_message(int level, const char *msg) {
45
+ switch (level) {
46
+ case 0:
47
+ pr_err("simple_module: ERROR: %s\n", msg);
48
+ break;
49
+ case 1:
50
+ pr_info("simple_module: INFO: %s\n", msg);
51
+ break;
52
+ case 2:
53
+ pr_debug("simple_module: DEBUG: %s\n", msg);
54
+ break;
55
+ default:
56
+ pr_warn("simple_module: WARN: %s\n", msg);
57
+ }
58
+ }
59
+
60
+ /**
61
+ * @brief Module initialization function
62
+ * @return 0 on success, negative error code on failure
63
+ */
64
+ static int __init simple_module_init(void) {
65
+ pr_info("simple_module: Initializing module\n");
66
+ pr_info("simple_module: Debug level: %d\n", debug_level);
67
+ pr_info("simple_module: Message: %s\n", message);
68
+
69
+ // Allocate some memory (example)
70
+ module_data = kmalloc(1024, GFP_KERNEL);
71
+ if (!module_data) {
72
+ pr_err("simple_module: Failed to allocate memory\n");
73
+ return -ENOMEM;
74
+ }
75
+
76
+ if (debug_level >= 1) {
77
+ log_message(1, "Module data allocated successfully");
78
+ }
79
+
80
+ // Simulate initialization work
81
+ if (debug_level >= 2) {
82
+ log_message(2, "Performing detailed initialization");
83
+ }
84
+
85
+ pr_info("simple_module: Module loaded successfully\n");
86
+ return 0;
87
+ }
88
+
89
+ /**
90
+ * @brief Module cleanup function
91
+ */
92
+ static void __exit simple_module_exit(void) {
93
+ pr_info("simple_module: Cleaning up module\n");
94
+
95
+ // Free allocated memory
96
+ if (module_data) {
97
+ kfree(module_data);
98
+ module_data = NULL;
99
+
100
+ if (debug_level >= 1) {
101
+ log_message(1, "Module data freed");
102
+ }
103
+ }
104
+
105
+ pr_info("simple_module: Module unloaded\n");
106
+ }
107
+
108
+ // Register init and exit functions
109
+ module_init(simple_module_init);
110
+ module_exit(simple_module_exit);
111
+
@@ -0,0 +1,62 @@
1
+ # Makefile for Legacy Maintenance Examples
2
+
3
+ CC = gcc
4
+ CFLAGS_C89 = -Wall -Wextra -std=c89 -pedantic -DUSE_C89
5
+ CFLAGS_C99 = -Wall -Wextra -std=c99 -pedantic
6
+ CFLAGS_C11 = -Wall -Wextra -std=c11 -pedantic
7
+
8
+ .PHONY: all clean test compare
9
+
10
+ all: migration-c89 migration-c11 compatibility
11
+
12
+ # C89 version of migration example
13
+ migration-c89: c89-to-c11-migration.c
14
+ $(CC) $(CFLAGS_C89) -o $@ $<
15
+
16
+ # C11 version of migration example
17
+ migration-c11: c89-to-c11-migration.c
18
+ $(CC) $(CFLAGS_C11) -o $@ $<
19
+
20
+ # Compatibility layer
21
+ compatibility: compatibility-layer.c
22
+ $(CC) $(CFLAGS_C11) -o $@ $<
23
+
24
+ clean:
25
+ rm -f migration-c89 migration-c11 compatibility *.o
26
+
27
+ test: all
28
+ @echo "=== Testing C89 Version ==="
29
+ ./migration-c89
30
+ @echo ""
31
+ @echo "=== Testing C11 Version ==="
32
+ ./migration-c11
33
+ @echo ""
34
+ @echo "=== Testing Compatibility Layer ==="
35
+ ./compatibility
36
+
37
+ compare: all
38
+ @echo "Comparing C89 vs C11 output:"
39
+ @echo ""
40
+ @echo "--- C89 Output ---"
41
+ @./migration-c89 > /tmp/c89-output.txt 2>&1
42
+ @cat /tmp/c89-output.txt
43
+ @echo ""
44
+ @echo "--- C11 Output ---"
45
+ @./migration-c11 > /tmp/c11-output.txt 2>&1
46
+ @cat /tmp/c11-output.txt
47
+ @echo ""
48
+ @echo "--- Differences ---"
49
+ @diff -u /tmp/c89-output.txt /tmp/c11-output.txt || true
50
+
51
+ help:
52
+ @echo "Legacy Maintenance Examples Makefile"
53
+ @echo "====================================="
54
+ @echo "Targets:"
55
+ @echo " all - Build all examples"
56
+ @echo " migration-c89 - Build C89 version"
57
+ @echo " migration-c11 - Build C11 version"
58
+ @echo " compatibility - Build compatibility layer"
59
+ @echo " clean - Remove build artifacts"
60
+ @echo " test - Run all examples"
61
+ @echo " compare - Compare C89 vs C11 output"
62
+
@@ -0,0 +1,255 @@
1
+ # Legacy Code Maintenance Examples
2
+
3
+ This directory contains examples for maintaining and modernizing legacy C code.
4
+
5
+ ## Examples
6
+
7
+ ### 1. c89-to-c11-migration.c
8
+ Demonstrates migration from C89 to C11:
9
+ - Variable declaration improvements
10
+ - Designated initializers
11
+ - Static assertions
12
+ - Flexible array members
13
+ - Inline functions
14
+ - Anonymous unions/structs
15
+
16
+ **Key Concepts:**
17
+ - Compile with both standards to verify compatibility
18
+ - Use conditional compilation for gradual migration
19
+ - Leverage C11 features for cleaner code
20
+ - Maintain backward compatibility when needed
21
+
22
+ ### 2. compatibility-layer.c
23
+ Cross-platform and cross-standard compatibility:
24
+ - Compiler detection
25
+ - Platform detection
26
+ - C standard detection
27
+ - Feature compatibility macros
28
+ - Safe string functions
29
+ - Platform-specific abstractions
30
+
31
+ **Key Concepts:**
32
+ - Abstract platform differences
33
+ - Provide fallbacks for missing features
34
+ - Use feature detection over version checks
35
+ - Create consistent API across platforms
36
+
37
+ ## Building
38
+
39
+ ```bash
40
+ # Build all examples
41
+ make
42
+
43
+ # Build specific versions
44
+ make migration-c89 # C89 version
45
+ make migration-c11 # C11 version
46
+ make compatibility # Compatibility layer
47
+
48
+ # Clean
49
+ make clean
50
+
51
+ # Run tests
52
+ make test
53
+
54
+ # Compare C89 vs C11 output
55
+ make compare
56
+ ```
57
+
58
+ ## Migration Strategy
59
+
60
+ ### Phase 1: Assessment
61
+ 1. Identify C standard currently used
62
+ 2. Check compiler compatibility
63
+ 3. Review platform dependencies
64
+ 4. List deprecated features
65
+
66
+ ### Phase 2: Preparation
67
+ 1. Add compatibility layer
68
+ 2. Create test suite
69
+ 3. Document platform-specific code
70
+ 4. Set up build for multiple standards
71
+
72
+ ### Phase 3: Gradual Migration
73
+ 1. Start with isolated modules
74
+ 2. Use conditional compilation
75
+ 3. Test thoroughly at each step
76
+ 4. Update documentation
77
+
78
+ ### Phase 4: Modernization
79
+ 1. Adopt C11 features
80
+ 2. Remove workarounds
81
+ 3. Improve type safety
82
+ 4. Enhance error handling
83
+
84
+ ## C89 to C11 Feature Comparison
85
+
86
+ ### Variable Declarations
87
+
88
+ **C89:**
89
+ ```c
90
+ void func(void) {
91
+ int i;
92
+ int sum = 0;
93
+
94
+ for (i = 0; i < 10; i++) {
95
+ sum += i;
96
+ }
97
+ }
98
+ ```
99
+
100
+ **C11:**
101
+ ```c
102
+ void func(void) {
103
+ int sum = 0;
104
+
105
+ for (int i = 0; i < 10; i++) {
106
+ sum += i;
107
+ }
108
+ }
109
+ ```
110
+
111
+ ### Designated Initializers
112
+
113
+ **C89:**
114
+ ```c
115
+ struct Point p = {10, 20, 30}; /* Must be in order */
116
+ ```
117
+
118
+ **C11:**
119
+ ```c
120
+ struct Point p = {.x = 10, .z = 30, .y = 20}; /* Any order */
121
+ ```
122
+
123
+ ### Static Assertions
124
+
125
+ **C89:**
126
+ ```c
127
+ /* Runtime check only */
128
+ if (sizeof(int) != 4) {
129
+ abort();
130
+ }
131
+ ```
132
+
133
+ **C11:**
134
+ ```c
135
+ /* Compile-time check */
136
+ _Static_assert(sizeof(int) == 4, "int must be 4 bytes");
137
+ ```
138
+
139
+ ### Inline Functions
140
+
141
+ **C89:**
142
+ ```c
143
+ #define MAX(a, b) ((a) > (b) ? (a) : (b)) /* Macro */
144
+ ```
145
+
146
+ **C11:**
147
+ ```c
148
+ static inline int max(int a, int b) { /* Type-safe */
149
+ return a > b ? a : b;
150
+ }
151
+ ```
152
+
153
+ ## Compatibility Patterns
154
+
155
+ ### 1. Feature Detection
156
+
157
+ ```c
158
+ #if __STDC_VERSION__ >= 201112L
159
+ /* C11 code */
160
+ #elif __STDC_VERSION__ >= 199901L
161
+ /* C99 code */
162
+ #else
163
+ /* C89 code */
164
+ #endif
165
+ ```
166
+
167
+ ### 2. Compiler-Specific Features
168
+
169
+ ```c
170
+ #if defined(__GNUC__)
171
+ #define INLINE __inline__
172
+ #elif defined(_MSC_VER)
173
+ #define INLINE __inline
174
+ #else
175
+ #define INLINE
176
+ #endif
177
+ ```
178
+
179
+ ### 3. Platform Abstraction
180
+
181
+ ```c
182
+ #ifdef _WIN32
183
+ #include <windows.h>
184
+ #define sleep_ms(ms) Sleep(ms)
185
+ #else
186
+ #include <unistd.h>
187
+ #define sleep_ms(ms) usleep((ms) * 1000)
188
+ #endif
189
+ ```
190
+
191
+ ## Best Practices
192
+
193
+ 1. **Maintain Compatibility**
194
+ - Support multiple C standards
195
+ - Test on all target platforms
196
+ - Provide fallbacks for missing features
197
+ - Document requirements
198
+
199
+ 2. **Gradual Migration**
200
+ - Migrate one module at a time
201
+ - Keep old and new code working
202
+ - Use feature flags
203
+ - Extensive testing
204
+
205
+ 3. **Documentation**
206
+ - Document platform differences
207
+ - Note compiler requirements
208
+ - Explain workarounds
209
+ - Provide migration guide
210
+
211
+ 4. **Testing**
212
+ - Test on all platforms
213
+ - Test with different compilers
214
+ - Test different C standards
215
+ - Regression testing
216
+
217
+ ## Common Pitfalls
218
+
219
+ 1. **Assuming C99/C11 Features**
220
+ ```c
221
+ // WRONG - Not available in C89
222
+ for (int i = 0; i < 10; i++) { }
223
+
224
+ // CORRECT - Compatible with C89
225
+ int i;
226
+ for (i = 0; i < 10; i++) { }
227
+ ```
228
+
229
+ 2. **Platform-Specific Code**
230
+ ```c
231
+ // WRONG - Windows-only
232
+ Sleep(1000);
233
+
234
+ // CORRECT - Abstracted
235
+ compat_sleep_ms(1000);
236
+ ```
237
+
238
+ 3. **Compiler Extensions**
239
+ ```c
240
+ // WRONG - GCC-specific
241
+ int array[n]; /* VLA */
242
+
243
+ // CORRECT - Standard C
244
+ int *array = malloc(n * sizeof(int));
245
+ ```
246
+
247
+ ## References
248
+
249
+ - ISO/IEC 9899:1990 (C89/C90)
250
+ - ISO/IEC 9899:1999 (C99)
251
+ - ISO/IEC 9899:2011 (C11)
252
+ - "C Programming: A Modern Approach" by K. N. King
253
+ - GCC Compatibility: https://gcc.gnu.org/
254
+ - MSVC Compatibility: https://docs.microsoft.com/en-us/cpp/
255
+