@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.
- package/augment-extensions/coding-standards/c/CHANGELOG.md +55 -0
- package/augment-extensions/coding-standards/c/LICENSE +22 -0
- package/augment-extensions/coding-standards/c/README.md +167 -0
- package/augment-extensions/coding-standards/c/config/defaults.json +26 -0
- package/augment-extensions/coding-standards/c/config/examples/embedded.yaml +25 -0
- package/augment-extensions/coding-standards/c/config/examples/systems.json +31 -0
- package/augment-extensions/coding-standards/c/config/schema.json +244 -0
- package/augment-extensions/coding-standards/c/docs/API.md +613 -0
- package/augment-extensions/coding-standards/c/docs/CONFIGURATION.md +259 -0
- package/augment-extensions/coding-standards/c/docs/USER_GUIDE.md +567 -0
- package/augment-extensions/coding-standards/c/examples/drivers/Makefile +33 -0
- package/augment-extensions/coding-standards/c/examples/drivers/README.md +192 -0
- package/augment-extensions/coding-standards/c/examples/drivers/dma-example.c +224 -0
- package/augment-extensions/coding-standards/c/examples/drivers/example.dts +64 -0
- package/augment-extensions/coding-standards/c/examples/drivers/platform-driver.c +174 -0
- package/augment-extensions/coding-standards/c/examples/embedded/README.md +167 -0
- package/augment-extensions/coding-standards/c/examples/embedded/gpio-control.c +172 -0
- package/augment-extensions/coding-standards/c/examples/embedded/timer-isr.c +198 -0
- package/augment-extensions/coding-standards/c/examples/embedded/uart-communication.c +212 -0
- package/augment-extensions/coding-standards/c/examples/kernel/Makefile +82 -0
- package/augment-extensions/coding-standards/c/examples/kernel/README.md +168 -0
- package/augment-extensions/coding-standards/c/examples/kernel/char-device.c +198 -0
- package/augment-extensions/coding-standards/c/examples/kernel/proc-file.c +131 -0
- package/augment-extensions/coding-standards/c/examples/kernel/simple-module.c +111 -0
- package/augment-extensions/coding-standards/c/examples/legacy/Makefile +62 -0
- package/augment-extensions/coding-standards/c/examples/legacy/README.md +255 -0
- package/augment-extensions/coding-standards/c/examples/legacy/c89-to-c11-migration.c +268 -0
- package/augment-extensions/coding-standards/c/examples/legacy/compatibility-layer.c +239 -0
- package/augment-extensions/coding-standards/c/examples/networking/Makefile +35 -0
- package/augment-extensions/coding-standards/c/examples/networking/README.md +207 -0
- package/augment-extensions/coding-standards/c/examples/networking/protocol-parser.c +270 -0
- package/augment-extensions/coding-standards/c/examples/networking/tcp-server.c +197 -0
- package/augment-extensions/coding-standards/c/examples/networking/udp-multicast.c +220 -0
- package/augment-extensions/coding-standards/c/examples/realtime/Makefile +53 -0
- package/augment-extensions/coding-standards/c/examples/realtime/README.md +199 -0
- package/augment-extensions/coding-standards/c/examples/realtime/deadline-monitoring.c +260 -0
- package/augment-extensions/coding-standards/c/examples/realtime/priority-scheduling.c +258 -0
- package/augment-extensions/coding-standards/c/examples/systems/Makefile +34 -0
- package/augment-extensions/coding-standards/c/examples/systems/README.md +123 -0
- package/augment-extensions/coding-standards/c/examples/systems/ipc-pipes.c +181 -0
- package/augment-extensions/coding-standards/c/examples/systems/process-management.c +153 -0
- package/augment-extensions/coding-standards/c/examples/systems/signal-handling.c +162 -0
- package/augment-extensions/coding-standards/c/module.json +149 -0
- package/augment-extensions/coding-standards/c/rules/categories/drivers.md +635 -0
- package/augment-extensions/coding-standards/c/rules/categories/embedded.md +510 -0
- package/augment-extensions/coding-standards/c/rules/categories/kernel.md +653 -0
- package/augment-extensions/coding-standards/c/rules/categories/legacy.md +526 -0
- package/augment-extensions/coding-standards/c/rules/categories/networking.md +735 -0
- package/augment-extensions/coding-standards/c/rules/categories/realtime.md +631 -0
- package/augment-extensions/coding-standards/c/rules/categories/systems.md +586 -0
- package/augment-extensions/coding-standards/c/rules/universal/const-correctness.md +275 -0
- package/augment-extensions/coding-standards/c/rules/universal/documentation.md +251 -0
- package/augment-extensions/coding-standards/c/rules/universal/error-handling.md +250 -0
- package/augment-extensions/coding-standards/c/rules/universal/header-guards.md +254 -0
- package/augment-extensions/coding-standards/c/rules/universal/memory-safety.md +233 -0
- package/augment-extensions/coding-standards/c/rules/universal/naming.md +146 -0
- package/augment-extensions/coding-standards/c/src/conflict-detector.ts +461 -0
- package/augment-extensions/coding-standards/c/src/prompt-generator.ts +307 -0
- package/augment-extensions/coding-standards/c/src/rule-evaluator.ts +307 -0
- package/augment-extensions/coding-standards/c/src/rule-override.ts +427 -0
- package/augment-extensions/coding-standards/c/src/template-engine.ts +217 -0
- package/augment-extensions/coding-standards/c/templates/prompts/drivers.txt +191 -0
- package/augment-extensions/coding-standards/c/templates/prompts/embedded.txt +164 -0
- package/augment-extensions/coding-standards/c/templates/prompts/kernel.txt +175 -0
- package/augment-extensions/coding-standards/c/templates/prompts/legacy.txt +280 -0
- package/augment-extensions/coding-standards/c/templates/prompts/networking.txt +259 -0
- package/augment-extensions/coding-standards/c/templates/prompts/realtime.txt +219 -0
- package/augment-extensions/coding-standards/c/templates/prompts/systems.txt +147 -0
- package/augment-extensions/coding-standards/c/tests/integration/category-specific.test.ts +356 -0
- package/augment-extensions/coding-standards/c/tests/integration/end-to-end-workflow.test.ts +377 -0
- package/augment-extensions/coding-standards/c/tests/performance/benchmarks.test.ts +407 -0
- package/augment-extensions/coding-standards/c/tests/unit/config-manager.test.ts +345 -0
- package/augment-extensions/coding-standards/c/tests/unit/conflict-detector.test.ts +294 -0
- package/augment-extensions/coding-standards/c/tests/unit/prompt-generator.test.ts +174 -0
- package/augment-extensions/coding-standards/c/tests/unit/registry.test.ts +313 -0
- package/augment-extensions/coding-standards/c/tests/unit/rule-evaluator.test.ts +318 -0
- package/augment-extensions/coding-standards/c/tests/unit/rule-override.test.ts +326 -0
- package/augment-extensions/coding-standards/c/tests/unit/template-engine.test.ts +314 -0
- package/augment-extensions/coding-standards/go/CHARACTER-COUNT-REPORT.md +135 -0
- package/augment-extensions/coding-standards/go/PHASE1-COMPLETION.md +146 -0
- package/augment-extensions/coding-standards/go/PHASE4-COMPLETION.md +184 -0
- package/augment-extensions/coding-standards/go/README.md +200 -0
- package/augment-extensions/coding-standards/go/VALIDATION-CHECKLIST.md +154 -0
- package/augment-extensions/coding-standards/go/config/examples/example-cli.json +15 -0
- package/augment-extensions/coding-standards/go/config/examples/example-microservices.json +21 -0
- package/augment-extensions/coding-standards/go/config/examples/example-multi-category.yaml +24 -0
- package/augment-extensions/coding-standards/go/config/examples/example-web.json +15 -0
- package/augment-extensions/coding-standards/go/config/schema.json +110 -0
- package/augment-extensions/coding-standards/go/docs/CATEGORIES.md +221 -0
- package/augment-extensions/coding-standards/go/docs/CONFIGURATION.md +198 -0
- package/augment-extensions/coding-standards/go/docs/TROUBLESHOOTING.md +285 -0
- package/augment-extensions/coding-standards/go/examples/cli/cobra-app.go +287 -0
- package/augment-extensions/coding-standards/go/examples/cloud-native-app.go +217 -0
- package/augment-extensions/coding-standards/go/examples/devops-tool.go +250 -0
- package/augment-extensions/coding-standards/go/examples/distributed-system.go +247 -0
- package/augment-extensions/coding-standards/go/examples/microservices/grpc-service.go +253 -0
- package/augment-extensions/coding-standards/go/examples/rest-api.go +270 -0
- package/augment-extensions/coding-standards/go/examples/web/http-server.go +224 -0
- package/augment-extensions/coding-standards/go/module.json +139 -0
- package/augment-extensions/coding-standards/go/rules/categories/api-development/api-versioning.md +149 -0
- package/augment-extensions/coding-standards/go/rules/categories/api-development/rate-limiting.md +209 -0
- package/augment-extensions/coding-standards/go/rules/categories/api-development/rest-api-design.md +183 -0
- package/augment-extensions/coding-standards/go/rules/categories/cloud-native/cloud-config.md +193 -0
- package/augment-extensions/coding-standards/go/rules/categories/cloud-native/health-checks.md +231 -0
- package/augment-extensions/coding-standards/go/rules/categories/cloud-native/kubernetes.md +180 -0
- package/augment-extensions/coding-standards/go/rules/categories/devops-tooling/automation.md +179 -0
- package/augment-extensions/coding-standards/go/rules/categories/devops-tooling/ci-cd-integration.md +147 -0
- package/augment-extensions/coding-standards/go/rules/categories/devops-tooling/infrastructure-as-code.md +231 -0
- package/augment-extensions/coding-standards/go/rules/categories/distributed-systems/caching.md +150 -0
- package/augment-extensions/coding-standards/go/rules/categories/distributed-systems/consensus.md +187 -0
- package/augment-extensions/coding-standards/go/rules/categories/distributed-systems/event-sourcing.md +246 -0
- package/augment-extensions/coding-standards/go/rules/cli/command-parsing.md +264 -0
- package/augment-extensions/coding-standards/go/rules/cli/configuration.md +268 -0
- package/augment-extensions/coding-standards/go/rules/cli/cross-platform.md +324 -0
- package/augment-extensions/coding-standards/go/rules/microservices/distributed-tracing.md +253 -0
- package/augment-extensions/coding-standards/go/rules/microservices/grpc.md +257 -0
- package/augment-extensions/coding-standards/go/rules/microservices/metrics.md +278 -0
- package/augment-extensions/coding-standards/go/rules/microservices/service-discovery.md +249 -0
- package/augment-extensions/coding-standards/go/rules/universal/code-organization.md +221 -0
- package/augment-extensions/coding-standards/go/rules/universal/documentation.md +269 -0
- package/augment-extensions/coding-standards/go/rules/universal/performance.md +323 -0
- package/augment-extensions/coding-standards/go/rules/universal/testing.md +162 -0
- package/augment-extensions/coding-standards/go/rules/web/graceful-shutdown.md +249 -0
- package/augment-extensions/coding-standards/go/rules/web/http-handlers.md +164 -0
- package/augment-extensions/coding-standards/go/rules/web/middleware.md +234 -0
- package/augment-extensions/coding-standards/go/rules/web/routing.md +251 -0
- package/augment-extensions/coding-standards/go/templates/prompts/api.md +160 -0
- package/augment-extensions/coding-standards/go/templates/prompts/cli.md +225 -0
- package/augment-extensions/coding-standards/go/templates/prompts/cloud-native.md +121 -0
- package/augment-extensions/coding-standards/go/templates/prompts/devops.md +146 -0
- package/augment-extensions/coding-standards/go/templates/prompts/distributed.md +133 -0
- package/augment-extensions/coding-standards/go/templates/prompts/microservices.md +225 -0
- package/augment-extensions/coding-standards/go/templates/prompts/web.md +181 -0
- package/augment-extensions/coding-standards/go/tests/integration/module-integration.test.ts +164 -0
- package/augment-extensions/coding-standards/go/tests/unit/category-selection.test.ts +147 -0
- package/augment-extensions/coding-standards/go/tests/unit/module-structure.test.ts +154 -0
- package/augment-extensions/coding-standards/go/tests/validate-character-count.ps1 +13 -0
- package/augment-extensions/coding-standards/go/tests/validate-examples.ps1 +148 -0
- package/augment-extensions/coding-standards/go/tests/validate-examples.sh +135 -0
- package/cli/dist/analysis/ast-parser.d.ts +47 -0
- package/cli/dist/analysis/ast-parser.d.ts.map +1 -0
- package/cli/dist/analysis/ast-parser.js +161 -0
- package/cli/dist/analysis/ast-parser.js.map +1 -0
- package/cli/dist/analysis/complexity-analyzer.d.ts +27 -0
- package/cli/dist/analysis/complexity-analyzer.d.ts.map +1 -0
- package/cli/dist/analysis/complexity-analyzer.js +189 -0
- package/cli/dist/analysis/complexity-analyzer.js.map +1 -0
- package/cli/dist/analysis/dependency-analyzer.d.ts +23 -0
- package/cli/dist/analysis/dependency-analyzer.d.ts.map +1 -0
- package/cli/dist/analysis/dependency-analyzer.js +237 -0
- package/cli/dist/analysis/dependency-analyzer.js.map +1 -0
- package/cli/dist/analysis/index.d.ts +9 -0
- package/cli/dist/analysis/index.d.ts.map +1 -0
- package/cli/dist/analysis/index.js +25 -0
- package/cli/dist/analysis/index.js.map +1 -0
- package/cli/dist/analysis/security-scanner.d.ts +11 -0
- package/cli/dist/analysis/security-scanner.d.ts.map +1 -0
- package/cli/dist/analysis/security-scanner.js +294 -0
- package/cli/dist/analysis/security-scanner.js.map +1 -0
- package/cli/dist/analysis/types.d.ts +151 -0
- package/cli/dist/analysis/types.d.ts.map +1 -0
- package/cli/dist/analysis/types.js +6 -0
- package/cli/dist/analysis/types.js.map +1 -0
- package/cli/dist/cli.js +24 -0
- package/cli/dist/cli.js.map +1 -1
- package/cli/dist/commands/code-analysis.d.ts +11 -0
- package/cli/dist/commands/code-analysis.d.ts.map +1 -0
- package/cli/dist/commands/code-analysis.js +412 -0
- package/cli/dist/commands/code-analysis.js.map +1 -0
- package/modules.md +99 -3
- package/package.json +14 -2
- package/cli/dist/commands/agent.d.ts +0 -37
- package/cli/dist/commands/agent.d.ts.map +0 -1
- package/cli/dist/commands/agent.js +0 -222
- package/cli/dist/commands/agent.js.map +0 -1
- package/cli/dist/commands/beads.d.ts +0 -64
- package/cli/dist/commands/beads.d.ts.map +0 -1
- package/cli/dist/commands/beads.js +0 -377
- package/cli/dist/commands/beads.js.map +0 -1
- package/cli/dist/commands/change.d.ts +0 -54
- package/cli/dist/commands/change.d.ts.map +0 -1
- package/cli/dist/commands/change.js +0 -243
- package/cli/dist/commands/change.js.map +0 -1
- package/cli/dist/commands/clean.d.ts +0 -15
- package/cli/dist/commands/clean.d.ts.map +0 -1
- package/cli/dist/commands/clean.js +0 -63
- package/cli/dist/commands/clean.js.map +0 -1
- package/cli/dist/commands/clone.d.ts +0 -15
- package/cli/dist/commands/clone.d.ts.map +0 -1
- package/cli/dist/commands/clone.js +0 -49
- package/cli/dist/commands/clone.js.map +0 -1
- package/cli/dist/commands/config.d.ts +0 -33
- package/cli/dist/commands/config.d.ts.map +0 -1
- package/cli/dist/commands/config.js +0 -166
- package/cli/dist/commands/config.js.map +0 -1
- package/cli/dist/commands/context.d.ts +0 -38
- package/cli/dist/commands/context.d.ts.map +0 -1
- package/cli/dist/commands/context.js +0 -205
- package/cli/dist/commands/context.js.map +0 -1
- package/cli/dist/commands/create.d.ts +0 -18
- package/cli/dist/commands/create.d.ts.map +0 -1
- package/cli/dist/commands/create.js +0 -178
- package/cli/dist/commands/create.js.map +0 -1
- package/cli/dist/commands/diff.d.ts +0 -19
- package/cli/dist/commands/diff.d.ts.map +0 -1
- package/cli/dist/commands/diff.js +0 -104
- package/cli/dist/commands/diff.js.map +0 -1
- package/cli/dist/commands/doctor.d.ts +0 -14
- package/cli/dist/commands/doctor.d.ts.map +0 -1
- package/cli/dist/commands/doctor.js +0 -62
- package/cli/dist/commands/doctor.js.map +0 -1
- package/cli/dist/commands/export.d.ts +0 -28
- package/cli/dist/commands/export.d.ts.map +0 -1
- package/cli/dist/commands/export.js +0 -135
- package/cli/dist/commands/export.js.map +0 -1
- package/cli/dist/commands/import.d.ts +0 -23
- package/cli/dist/commands/import.d.ts.map +0 -1
- package/cli/dist/commands/import.js +0 -118
- package/cli/dist/commands/import.js.map +0 -1
- package/cli/dist/commands/prompt.d.ts +0 -45
- package/cli/dist/commands/prompt.d.ts.map +0 -1
- package/cli/dist/commands/prompt.js +0 -223
- package/cli/dist/commands/prompt.js.map +0 -1
- package/cli/dist/commands/spec.d.ts +0 -57
- package/cli/dist/commands/spec.d.ts.map +0 -1
- package/cli/dist/commands/spec.js +0 -279
- package/cli/dist/commands/spec.js.map +0 -1
- package/cli/dist/commands/stats.d.ts +0 -18
- package/cli/dist/commands/stats.d.ts.map +0 -1
- package/cli/dist/commands/stats.js +0 -85
- package/cli/dist/commands/stats.js.map +0 -1
- package/cli/dist/commands/task.d.ts +0 -65
- package/cli/dist/commands/task.d.ts.map +0 -1
- package/cli/dist/commands/task.js +0 -282
- package/cli/dist/commands/task.js.map +0 -1
- package/cli/dist/commands/template.d.ts +0 -17
- package/cli/dist/commands/template.d.ts.map +0 -1
- package/cli/dist/commands/template.js +0 -55
- package/cli/dist/commands/template.js.map +0 -1
- package/cli/dist/utils/agent-config.d.ts +0 -129
- package/cli/dist/utils/agent-config.d.ts.map +0 -1
- package/cli/dist/utils/agent-config.js +0 -297
- package/cli/dist/utils/agent-config.js.map +0 -1
- package/cli/dist/utils/beads-graph.d.ts +0 -17
- package/cli/dist/utils/beads-graph.d.ts.map +0 -1
- package/cli/dist/utils/beads-graph.js +0 -150
- package/cli/dist/utils/beads-graph.js.map +0 -1
- package/cli/dist/utils/beads-integration.d.ts +0 -112
- package/cli/dist/utils/beads-integration.d.ts.map +0 -1
- package/cli/dist/utils/beads-integration.js +0 -312
- package/cli/dist/utils/beads-integration.js.map +0 -1
- package/cli/dist/utils/beads-reporter.d.ts +0 -17
- package/cli/dist/utils/beads-reporter.d.ts.map +0 -1
- package/cli/dist/utils/beads-reporter.js +0 -160
- package/cli/dist/utils/beads-reporter.js.map +0 -1
- package/cli/dist/utils/cache-manager.d.ts +0 -55
- package/cli/dist/utils/cache-manager.d.ts.map +0 -1
- package/cli/dist/utils/cache-manager.js +0 -150
- package/cli/dist/utils/cache-manager.js.map +0 -1
- package/cli/dist/utils/change-manager.d.ts +0 -70
- package/cli/dist/utils/change-manager.d.ts.map +0 -1
- package/cli/dist/utils/change-manager.js +0 -412
- package/cli/dist/utils/change-manager.js.map +0 -1
- package/cli/dist/utils/config-manager-enhanced.d.ts +0 -66
- package/cli/dist/utils/config-manager-enhanced.d.ts.map +0 -1
- package/cli/dist/utils/config-manager-enhanced.js +0 -77
- package/cli/dist/utils/config-manager-enhanced.js.map +0 -1
- package/cli/dist/utils/context-manager.d.ts +0 -96
- package/cli/dist/utils/context-manager.d.ts.map +0 -1
- package/cli/dist/utils/context-manager.js +0 -258
- package/cli/dist/utils/context-manager.js.map +0 -1
- package/cli/dist/utils/diff-engine.d.ts +0 -78
- package/cli/dist/utils/diff-engine.d.ts.map +0 -1
- package/cli/dist/utils/diff-engine.js +0 -233
- package/cli/dist/utils/diff-engine.js.map +0 -1
- package/cli/dist/utils/export-system.d.ts +0 -101
- package/cli/dist/utils/export-system.d.ts.map +0 -1
- package/cli/dist/utils/export-system.js +0 -289
- package/cli/dist/utils/export-system.js.map +0 -1
- package/cli/dist/utils/health-checker.d.ts +0 -66
- package/cli/dist/utils/health-checker.d.ts.map +0 -1
- package/cli/dist/utils/health-checker.js +0 -285
- package/cli/dist/utils/health-checker.js.map +0 -1
- package/cli/dist/utils/import-system.d.ts +0 -74
- package/cli/dist/utils/import-system.d.ts.map +0 -1
- package/cli/dist/utils/import-system.js +0 -317
- package/cli/dist/utils/import-system.js.map +0 -1
- package/cli/dist/utils/module-cloner.d.ts +0 -40
- package/cli/dist/utils/module-cloner.d.ts.map +0 -1
- package/cli/dist/utils/module-cloner.js +0 -136
- package/cli/dist/utils/module-cloner.js.map +0 -1
- package/cli/dist/utils/prompt-manager.d.ts +0 -90
- package/cli/dist/utils/prompt-manager.d.ts.map +0 -1
- package/cli/dist/utils/prompt-manager.js +0 -302
- package/cli/dist/utils/prompt-manager.js.map +0 -1
- package/cli/dist/utils/spec-manager.d.ts +0 -65
- package/cli/dist/utils/spec-manager.d.ts.map +0 -1
- package/cli/dist/utils/spec-manager.js +0 -329
- package/cli/dist/utils/spec-manager.js.map +0 -1
- package/cli/dist/utils/stats-collector.d.ts +0 -74
- package/cli/dist/utils/stats-collector.d.ts.map +0 -1
- package/cli/dist/utils/stats-collector.js +0 -164
- package/cli/dist/utils/stats-collector.js.map +0 -1
- package/cli/dist/utils/template-engine.d.ts +0 -47
- package/cli/dist/utils/template-engine.d.ts.map +0 -1
- package/cli/dist/utils/template-engine.js +0 -204
- package/cli/dist/utils/template-engine.js.map +0 -1
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
You are assisting with C legacy code maintenance and modernization.
|
|
2
|
+
|
|
3
|
+
## Context
|
|
4
|
+
- Category: {category}
|
|
5
|
+
- C Standard: {c_standard}
|
|
6
|
+
- Target: Maintaining and upgrading legacy C codebases
|
|
7
|
+
|
|
8
|
+
## Key Rules for Legacy Maintenance
|
|
9
|
+
|
|
10
|
+
### 1. Backward Compatibility
|
|
11
|
+
- Maintain API compatibility when possible
|
|
12
|
+
- Use feature test macros for conditional compilation
|
|
13
|
+
- Document breaking changes clearly
|
|
14
|
+
- Provide migration guides
|
|
15
|
+
- Support multiple C standards (C89, C99, C11)
|
|
16
|
+
|
|
17
|
+
### 2. Incremental Modernization
|
|
18
|
+
- Modernize in small, testable increments
|
|
19
|
+
- Add tests before refactoring
|
|
20
|
+
- Use compatibility layers for new features
|
|
21
|
+
- Keep old and new code paths temporarily
|
|
22
|
+
- Document modernization strategy
|
|
23
|
+
|
|
24
|
+
### 3. C89 to C11 Migration Patterns
|
|
25
|
+
- Replace implicit int with explicit types
|
|
26
|
+
- Add function prototypes
|
|
27
|
+
- Use stdint.h types instead of platform-specific
|
|
28
|
+
- Replace K&R function definitions with ANSI
|
|
29
|
+
- Add const correctness incrementally
|
|
30
|
+
|
|
31
|
+
### 4. Compatibility Layers
|
|
32
|
+
- Provide fallbacks for missing C99/C11 features
|
|
33
|
+
- Use preprocessor for conditional compilation
|
|
34
|
+
- Implement polyfills for standard functions
|
|
35
|
+
- Document platform-specific code
|
|
36
|
+
- Test on all target platforms
|
|
37
|
+
|
|
38
|
+
### 5. Documentation and Testing
|
|
39
|
+
- Document legacy behavior and quirks
|
|
40
|
+
- Add regression tests for existing functionality
|
|
41
|
+
- Document platform dependencies
|
|
42
|
+
- Create migration test suite
|
|
43
|
+
- Maintain changelog of modernization
|
|
44
|
+
|
|
45
|
+
{#if rules}
|
|
46
|
+
## Active Rules
|
|
47
|
+
{#each rules}
|
|
48
|
+
- {id}: {description}
|
|
49
|
+
{/each}
|
|
50
|
+
{/if}
|
|
51
|
+
|
|
52
|
+
## Example Pattern: C89 to C11 Migration
|
|
53
|
+
|
|
54
|
+
```c
|
|
55
|
+
/* BEFORE: C89 style */
|
|
56
|
+
#include <stdio.h>
|
|
57
|
+
|
|
58
|
+
/* K&R function definition */
|
|
59
|
+
int calculate(x, y)
|
|
60
|
+
int x;
|
|
61
|
+
int y;
|
|
62
|
+
{
|
|
63
|
+
int result; /* Declaration at start of block */
|
|
64
|
+
result = x + y;
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
void process_data(buffer, size)
|
|
69
|
+
char *buffer;
|
|
70
|
+
int size;
|
|
71
|
+
{
|
|
72
|
+
int i;
|
|
73
|
+
for (i = 0; i < size; i++) {
|
|
74
|
+
buffer[i] = process_byte(buffer[i]);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/* AFTER: C11 style */
|
|
79
|
+
#include <stdio.h>
|
|
80
|
+
#include <stdint.h>
|
|
81
|
+
#include <stdbool.h>
|
|
82
|
+
|
|
83
|
+
/* ANSI function prototype with explicit types */
|
|
84
|
+
int32_t calculate(int32_t x, int32_t y) {
|
|
85
|
+
/* Declaration at point of use (C99+) */
|
|
86
|
+
int32_t result = x + y;
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
void process_data(uint8_t *buffer, size_t size) {
|
|
91
|
+
/* Loop variable declared in for statement (C99+) */
|
|
92
|
+
for (size_t i = 0; i < size; i++) {
|
|
93
|
+
buffer[i] = process_byte(buffer[i]);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Example Pattern: Compatibility Layer
|
|
99
|
+
|
|
100
|
+
```c
|
|
101
|
+
/* compatibility.h - Provide C99/C11 features for older compilers */
|
|
102
|
+
|
|
103
|
+
#ifndef COMPATIBILITY_H
|
|
104
|
+
#define COMPATIBILITY_H
|
|
105
|
+
|
|
106
|
+
/* Feature test macros */
|
|
107
|
+
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
|
|
108
|
+
#define HAVE_C99 1
|
|
109
|
+
#endif
|
|
110
|
+
|
|
111
|
+
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
|
|
112
|
+
#define HAVE_C11 1
|
|
113
|
+
#endif
|
|
114
|
+
|
|
115
|
+
/* stdint.h types for pre-C99 */
|
|
116
|
+
#ifndef HAVE_C99
|
|
117
|
+
typedef signed char int8_t;
|
|
118
|
+
typedef unsigned char uint8_t;
|
|
119
|
+
typedef signed short int16_t;
|
|
120
|
+
typedef unsigned short uint16_t;
|
|
121
|
+
typedef signed int int32_t;
|
|
122
|
+
typedef unsigned int uint32_t;
|
|
123
|
+
typedef signed long long int64_t;
|
|
124
|
+
typedef unsigned long long uint64_t;
|
|
125
|
+
typedef unsigned long size_t;
|
|
126
|
+
#else
|
|
127
|
+
#include <stdint.h>
|
|
128
|
+
#endif
|
|
129
|
+
|
|
130
|
+
/* stdbool.h for pre-C99 */
|
|
131
|
+
#ifndef HAVE_C99
|
|
132
|
+
typedef enum { false = 0, true = 1 } bool;
|
|
133
|
+
#else
|
|
134
|
+
#include <stdbool.h>
|
|
135
|
+
#endif
|
|
136
|
+
|
|
137
|
+
/* inline keyword */
|
|
138
|
+
#ifndef HAVE_C99
|
|
139
|
+
#if defined(__GNUC__)
|
|
140
|
+
#define inline __inline__
|
|
141
|
+
#elif defined(_MSC_VER)
|
|
142
|
+
#define inline __inline
|
|
143
|
+
#else
|
|
144
|
+
#define inline
|
|
145
|
+
#endif
|
|
146
|
+
#endif
|
|
147
|
+
|
|
148
|
+
/* restrict keyword */
|
|
149
|
+
#ifndef HAVE_C99
|
|
150
|
+
#if defined(__GNUC__)
|
|
151
|
+
#define restrict __restrict__
|
|
152
|
+
#elif defined(_MSC_VER)
|
|
153
|
+
#define restrict __restrict
|
|
154
|
+
#else
|
|
155
|
+
#define restrict
|
|
156
|
+
#endif
|
|
157
|
+
#endif
|
|
158
|
+
|
|
159
|
+
/* Static assertions */
|
|
160
|
+
#ifdef HAVE_C11
|
|
161
|
+
#include <assert.h>
|
|
162
|
+
#define STATIC_ASSERT(cond, msg) _Static_assert(cond, msg)
|
|
163
|
+
#else
|
|
164
|
+
#define STATIC_ASSERT(cond, msg) \
|
|
165
|
+
typedef char static_assertion_##msg[(cond) ? 1 : -1]
|
|
166
|
+
#endif
|
|
167
|
+
|
|
168
|
+
#endif /* COMPATIBILITY_H */
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Example Pattern: Gradual Refactoring
|
|
172
|
+
|
|
173
|
+
```c
|
|
174
|
+
/* Step 1: Add new API alongside old API */
|
|
175
|
+
|
|
176
|
+
/* Legacy API - deprecated but still supported */
|
|
177
|
+
int old_process_data(char *buffer, int size) {
|
|
178
|
+
/* Old implementation */
|
|
179
|
+
return legacy_implementation(buffer, size);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/* New API - recommended */
|
|
183
|
+
int process_data_v2(uint8_t *buffer, size_t size) {
|
|
184
|
+
/* New, improved implementation */
|
|
185
|
+
if (!buffer || size == 0) {
|
|
186
|
+
return -1;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
for (size_t i = 0; i < size; i++) {
|
|
190
|
+
buffer[i] = process_byte(buffer[i]);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return 0;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/* Compatibility wrapper */
|
|
197
|
+
#ifndef DISABLE_LEGACY_API
|
|
198
|
+
int process_data(char *buffer, int size) {
|
|
199
|
+
/* Emit deprecation warning */
|
|
200
|
+
#ifdef __GNUC__
|
|
201
|
+
#warning "process_data is deprecated, use process_data_v2"
|
|
202
|
+
#endif
|
|
203
|
+
|
|
204
|
+
/* Forward to new implementation */
|
|
205
|
+
if (size < 0) {
|
|
206
|
+
return -1;
|
|
207
|
+
}
|
|
208
|
+
return process_data_v2((uint8_t*)buffer, (size_t)size);
|
|
209
|
+
}
|
|
210
|
+
#endif
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## Example Pattern: Platform Abstraction
|
|
214
|
+
|
|
215
|
+
```c
|
|
216
|
+
/* platform.h - Abstract platform differences */
|
|
217
|
+
|
|
218
|
+
#ifndef PLATFORM_H
|
|
219
|
+
#define PLATFORM_H
|
|
220
|
+
|
|
221
|
+
#include "compatibility.h"
|
|
222
|
+
|
|
223
|
+
/* Platform detection */
|
|
224
|
+
#if defined(_WIN32) || defined(_WIN64)
|
|
225
|
+
#define PLATFORM_WINDOWS 1
|
|
226
|
+
#elif defined(__linux__)
|
|
227
|
+
#define PLATFORM_LINUX 1
|
|
228
|
+
#elif defined(__APPLE__)
|
|
229
|
+
#define PLATFORM_MACOS 1
|
|
230
|
+
#else
|
|
231
|
+
#define PLATFORM_UNKNOWN 1
|
|
232
|
+
#endif
|
|
233
|
+
|
|
234
|
+
/* Platform-specific includes */
|
|
235
|
+
#ifdef PLATFORM_WINDOWS
|
|
236
|
+
#include <windows.h>
|
|
237
|
+
typedef HANDLE thread_t;
|
|
238
|
+
#else
|
|
239
|
+
#include <pthread.h>
|
|
240
|
+
typedef pthread_t thread_t;
|
|
241
|
+
#endif
|
|
242
|
+
|
|
243
|
+
/* Platform-specific functions */
|
|
244
|
+
static inline int platform_sleep_ms(uint32_t milliseconds) {
|
|
245
|
+
#ifdef PLATFORM_WINDOWS
|
|
246
|
+
Sleep(milliseconds);
|
|
247
|
+
return 0;
|
|
248
|
+
#else
|
|
249
|
+
struct timespec ts;
|
|
250
|
+
ts.tv_sec = milliseconds / 1000;
|
|
251
|
+
ts.tv_nsec = (milliseconds % 1000) * 1000000;
|
|
252
|
+
return nanosleep(&ts, NULL);
|
|
253
|
+
#endif
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
#endif /* PLATFORM_H */
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
{#if examples}
|
|
260
|
+
## Additional Examples
|
|
261
|
+
{#each examples}
|
|
262
|
+
|
|
263
|
+
### {title}
|
|
264
|
+
```c
|
|
265
|
+
{code}
|
|
266
|
+
```
|
|
267
|
+
{/each}
|
|
268
|
+
{/if}
|
|
269
|
+
|
|
270
|
+
## Common Pitfalls to Avoid
|
|
271
|
+
- Breaking API compatibility without notice
|
|
272
|
+
- Modernizing too much code at once
|
|
273
|
+
- Not testing on all target platforms
|
|
274
|
+
- Removing legacy code paths prematurely
|
|
275
|
+
- Not documenting migration strategy
|
|
276
|
+
- Ignoring platform-specific behavior
|
|
277
|
+
- Assuming C99/C11 features available
|
|
278
|
+
|
|
279
|
+
Generate legacy C code maintenance following these careful migration standards.
|
|
280
|
+
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
You are assisting with C network programming.
|
|
2
|
+
|
|
3
|
+
## Context
|
|
4
|
+
- Category: {category}
|
|
5
|
+
- C Standard: {c_standard}
|
|
6
|
+
- Target: Network applications using sockets API
|
|
7
|
+
|
|
8
|
+
## Key Rules for Network Programming
|
|
9
|
+
|
|
10
|
+
### 1. Socket Programming Best Practices
|
|
11
|
+
- Always check socket() return value for -1
|
|
12
|
+
- Use getaddrinfo() for address resolution (IPv4/IPv6 compatible)
|
|
13
|
+
- Set socket options appropriately (SO_REUSEADDR, etc.)
|
|
14
|
+
- Close sockets in all code paths
|
|
15
|
+
- Handle partial send/recv in loops
|
|
16
|
+
|
|
17
|
+
### 2. Endianness Handling
|
|
18
|
+
**CRITICAL**: Network byte order is big-endian
|
|
19
|
+
- Use htons() for host-to-network short (16-bit)
|
|
20
|
+
- Use htonl() for host-to-network long (32-bit)
|
|
21
|
+
- Use ntohs() for network-to-host short
|
|
22
|
+
- Use ntohl() for network-to-host long
|
|
23
|
+
- Never assume host byte order
|
|
24
|
+
|
|
25
|
+
### 3. Protocol Implementation
|
|
26
|
+
- Follow RFC specifications exactly
|
|
27
|
+
- Validate all input from network
|
|
28
|
+
- Implement proper state machines
|
|
29
|
+
- Handle protocol errors gracefully
|
|
30
|
+
- Document protocol version and extensions
|
|
31
|
+
|
|
32
|
+
### 4. Buffer Management
|
|
33
|
+
- Use fixed-size buffers with bounds checking
|
|
34
|
+
- Handle partial reads/writes
|
|
35
|
+
- Implement timeout mechanisms
|
|
36
|
+
- Prevent buffer overflows
|
|
37
|
+
- Use MSG_PEEK for protocol parsing
|
|
38
|
+
|
|
39
|
+
### 5. Non-Blocking I/O
|
|
40
|
+
- Use select(), poll(), or epoll() for multiplexing
|
|
41
|
+
- Handle EAGAIN/EWOULDBLOCK properly
|
|
42
|
+
- Set O_NONBLOCK flag correctly
|
|
43
|
+
- Implement proper timeout handling
|
|
44
|
+
- Use edge-triggered or level-triggered appropriately
|
|
45
|
+
|
|
46
|
+
{#if rules}
|
|
47
|
+
## Active Rules
|
|
48
|
+
{#each rules}
|
|
49
|
+
- {id}: {description}
|
|
50
|
+
{/each}
|
|
51
|
+
{/if}
|
|
52
|
+
|
|
53
|
+
## Example Pattern: TCP Server with Error Handling
|
|
54
|
+
|
|
55
|
+
```c
|
|
56
|
+
#include <sys/socket.h>
|
|
57
|
+
#include <netinet/in.h>
|
|
58
|
+
#include <arpa/inet.h>
|
|
59
|
+
#include <unistd.h>
|
|
60
|
+
#include <string.h>
|
|
61
|
+
#include <errno.h>
|
|
62
|
+
#include <stdio.h>
|
|
63
|
+
|
|
64
|
+
#define PORT 8080
|
|
65
|
+
#define BACKLOG 10
|
|
66
|
+
#define BUFFER_SIZE 1024
|
|
67
|
+
|
|
68
|
+
int create_tcp_server(void) {
|
|
69
|
+
int server_fd, opt = 1;
|
|
70
|
+
struct sockaddr_in address;
|
|
71
|
+
|
|
72
|
+
// Create socket
|
|
73
|
+
server_fd = socket(AF_INET, SOCK_STREAM, 0);
|
|
74
|
+
if (server_fd < 0) {
|
|
75
|
+
perror("socket");
|
|
76
|
+
return -1;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Set socket options
|
|
80
|
+
if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR,
|
|
81
|
+
&opt, sizeof(opt)) < 0) {
|
|
82
|
+
perror("setsockopt");
|
|
83
|
+
close(server_fd);
|
|
84
|
+
return -1;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Bind to address
|
|
88
|
+
memset(&address, 0, sizeof(address));
|
|
89
|
+
address.sin_family = AF_INET;
|
|
90
|
+
address.sin_addr.s_addr = INADDR_ANY;
|
|
91
|
+
address.sin_port = htons(PORT); // Host to network byte order
|
|
92
|
+
|
|
93
|
+
if (bind(server_fd, (struct sockaddr*)&address, sizeof(address)) < 0) {
|
|
94
|
+
perror("bind");
|
|
95
|
+
close(server_fd);
|
|
96
|
+
return -1;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Listen for connections
|
|
100
|
+
if (listen(server_fd, BACKLOG) < 0) {
|
|
101
|
+
perror("listen");
|
|
102
|
+
close(server_fd);
|
|
103
|
+
return -1;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return server_fd;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
ssize_t send_all(int sockfd, const void *buf, size_t len) {
|
|
110
|
+
size_t total_sent = 0;
|
|
111
|
+
ssize_t sent;
|
|
112
|
+
|
|
113
|
+
while (total_sent < len) {
|
|
114
|
+
sent = send(sockfd, (char*)buf + total_sent,
|
|
115
|
+
len - total_sent, 0);
|
|
116
|
+
|
|
117
|
+
if (sent < 0) {
|
|
118
|
+
if (errno == EINTR) {
|
|
119
|
+
continue; // Interrupted, retry
|
|
120
|
+
}
|
|
121
|
+
perror("send");
|
|
122
|
+
return -1;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
total_sent += sent;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return total_sent;
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Example Pattern: UDP Multicast
|
|
133
|
+
|
|
134
|
+
```c
|
|
135
|
+
#include <sys/socket.h>
|
|
136
|
+
#include <netinet/in.h>
|
|
137
|
+
#include <arpa/inet.h>
|
|
138
|
+
#include <string.h>
|
|
139
|
+
|
|
140
|
+
#define MULTICAST_GROUP "239.0.0.1"
|
|
141
|
+
#define MULTICAST_PORT 5000
|
|
142
|
+
|
|
143
|
+
int join_multicast_group(void) {
|
|
144
|
+
int sockfd;
|
|
145
|
+
struct sockaddr_in addr;
|
|
146
|
+
struct ip_mreq mreq;
|
|
147
|
+
|
|
148
|
+
// Create UDP socket
|
|
149
|
+
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
|
150
|
+
if (sockfd < 0) {
|
|
151
|
+
perror("socket");
|
|
152
|
+
return -1;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Allow multiple sockets to use the same port
|
|
156
|
+
int reuse = 1;
|
|
157
|
+
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR,
|
|
158
|
+
&reuse, sizeof(reuse)) < 0) {
|
|
159
|
+
perror("setsockopt SO_REUSEADDR");
|
|
160
|
+
close(sockfd);
|
|
161
|
+
return -1;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Bind to multicast port
|
|
165
|
+
memset(&addr, 0, sizeof(addr));
|
|
166
|
+
addr.sin_family = AF_INET;
|
|
167
|
+
addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
|
168
|
+
addr.sin_port = htons(MULTICAST_PORT);
|
|
169
|
+
|
|
170
|
+
if (bind(sockfd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
|
|
171
|
+
perror("bind");
|
|
172
|
+
close(sockfd);
|
|
173
|
+
return -1;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Join multicast group
|
|
177
|
+
mreq.imr_multiaddr.s_addr = inet_addr(MULTICAST_GROUP);
|
|
178
|
+
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
|
|
179
|
+
|
|
180
|
+
if (setsockopt(sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
|
|
181
|
+
&mreq, sizeof(mreq)) < 0) {
|
|
182
|
+
perror("setsockopt IP_ADD_MEMBERSHIP");
|
|
183
|
+
close(sockfd);
|
|
184
|
+
return -1;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return sockfd;
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Example Pattern: Protocol Parser with Endianness
|
|
192
|
+
|
|
193
|
+
```c
|
|
194
|
+
#include <stdint.h>
|
|
195
|
+
#include <arpa/inet.h>
|
|
196
|
+
#include <stdbool.h>
|
|
197
|
+
|
|
198
|
+
// Network protocol header (big-endian)
|
|
199
|
+
typedef struct __attribute__((packed)) {
|
|
200
|
+
uint16_t version;
|
|
201
|
+
uint16_t message_type;
|
|
202
|
+
uint32_t payload_length;
|
|
203
|
+
uint32_t sequence_number;
|
|
204
|
+
} protocol_header_t;
|
|
205
|
+
|
|
206
|
+
bool parse_protocol_header(const uint8_t *buffer, protocol_header_t *header) {
|
|
207
|
+
if (!buffer || !header) {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Convert from network byte order to host byte order
|
|
212
|
+
header->version = ntohs(*(uint16_t*)(buffer + 0));
|
|
213
|
+
header->message_type = ntohs(*(uint16_t*)(buffer + 2));
|
|
214
|
+
header->payload_length = ntohl(*(uint32_t*)(buffer + 4));
|
|
215
|
+
header->sequence_number = ntohl(*(uint32_t*)(buffer + 8));
|
|
216
|
+
|
|
217
|
+
// Validate header
|
|
218
|
+
if (header->version != 1) {
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (header->payload_length > MAX_PAYLOAD_SIZE) {
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
void build_protocol_header(uint8_t *buffer, const protocol_header_t *header) {
|
|
230
|
+
// Convert from host byte order to network byte order
|
|
231
|
+
*(uint16_t*)(buffer + 0) = htons(header->version);
|
|
232
|
+
*(uint16_t*)(buffer + 2) = htons(header->message_type);
|
|
233
|
+
*(uint32_t*)(buffer + 4) = htonl(header->payload_length);
|
|
234
|
+
*(uint32_t*)(buffer + 8) = htonl(header->sequence_number);
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
{#if examples}
|
|
239
|
+
## Additional Examples
|
|
240
|
+
{#each examples}
|
|
241
|
+
|
|
242
|
+
### {title}
|
|
243
|
+
```c
|
|
244
|
+
{code}
|
|
245
|
+
```
|
|
246
|
+
{/each}
|
|
247
|
+
{/if}
|
|
248
|
+
|
|
249
|
+
## Common Pitfalls to Avoid
|
|
250
|
+
- Forgetting endianness conversion (htons/ntohs)
|
|
251
|
+
- Not handling partial send/recv
|
|
252
|
+
- Ignoring socket errors
|
|
253
|
+
- Not closing sockets on error paths
|
|
254
|
+
- Buffer overflows from network input
|
|
255
|
+
- Not validating protocol data
|
|
256
|
+
- Blocking indefinitely without timeouts
|
|
257
|
+
|
|
258
|
+
Generate network C code following these standards.
|
|
259
|
+
|