ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
strings/main.c
Go to the documentation of this file.
1
15
16#include <stdio.h>
17#include <stdlib.h>
18#include <string.h>
19#ifdef _WIN32
21#else
22#include <getopt.h>
23#endif
24#include <sodium.h>
28
29#define SESSION_STRING_BUFFER_SIZE 40
30#define ACDS_MAX_UNIQUE_SESSIONS (2500LL * 5000LL * 5000LL)
31
32int main(int argc, char *argv[]) {
33 long long count = 1;
34 int dump_adjectives = 0;
35 int dump_nouns = 0;
36
37 static struct option long_options[] = {{"count", required_argument, 0, 'n'},
38 {"dump-adjectives", no_argument, 0, 'a'},
39 {"dump-nouns", no_argument, 0, 'o'},
40 {"help", no_argument, 0, 'h'},
41 {0, 0, 0, 0}};
42
43 int opt;
44 while ((opt = getopt_long(argc, argv, "n:aoh", long_options, NULL)) != -1) {
45 switch (opt) {
46 case 'n':
47 count = strtoll(optarg, NULL, 10);
48 break;
49 case 'a':
50 dump_adjectives = 1;
51 break;
52 case 'o':
53 dump_nouns = 1;
54 break;
55 case 'h':
56 printf("Usage: ascii-chat-strings [OPTIONS]\n");
57 printf("Generate memorable session strings (adjective-noun-noun format)\n");
58 printf("\nOptions:\n");
59 printf(" -n, --count COUNT Generate COUNT session strings (default: 1)\n");
60 printf(" -a, --dump-adjectives Dump adjectives list as JavaScript\n");
61 printf(" -o, --dump-nouns Dump nouns list as JavaScript\n");
62 printf(" -h, --help Show this help message\n");
63 return 0;
64 default:
65 return ERROR_USAGE;
66 }
67 }
68
69 // Handle dump modes
70 if (dump_adjectives) {
71 printf("export const adjectives = [\n");
72 for (size_t i = 0; i < adjectives_count; i++) {
73 printf(" \"%s\"%s\n", adjectives[i], (i < adjectives_count - 1) ? "," : "");
74 }
75 printf("];\n");
76 printf("export const adjectives_count = %zu;\n", adjectives_count);
77 return 0;
78 }
79
80 if (dump_nouns) {
81 printf("export const nouns = [\n");
82 for (size_t i = 0; i < nouns_count; i++) {
83 printf(" \"%s\"%s\n", nouns[i], (i < nouns_count - 1) ? "," : "");
84 }
85 printf("];\n");
86 printf("export const nouns_count = %zu;\n", nouns_count);
87 return 0;
88 }
89
90 // Normal session string generation
91 if (count <= 0 || (long long)count > ACDS_MAX_UNIQUE_SESSIONS) {
92 return ERROR_USAGE;
93 }
94
95 // Generate session strings
96 for (long long i = 0; i < count; i++) {
97 uint32_t adj_idx = randombytes_uniform((uint32_t)adjectives_count);
98 uint32_t noun1_idx = randombytes_uniform((uint32_t)nouns_count);
99 uint32_t noun2_idx = randombytes_uniform((uint32_t)nouns_count);
100
101 printf("%s-%s-%s\n", adjectives[adj_idx], nouns[noun1_idx], nouns[noun2_idx]);
102 }
103
104 return 0;
105}
const char * adjectives[]
Array of English adjectives for ACDS session naming.
Definition adjectives.c:51
const size_t adjectives_count
Count of adjectives in the adjectives array.
Definition adjectives.c:411
Wordlist for generating friendly session identifiers in ACDS.
Error and exit codes - unified status values (0-255).
unsigned int uint32_t
Definition common.h:62
@ ERROR_USAGE
Definition error_codes.h:48
const char * nouns[]
Array of English nouns for session and client naming.
Definition nouns.c:55
const size_t nouns_count
Count of nouns in the nouns array.
Definition nouns.c:772
Wordlist and utilities for generating friendly session and client names.
🔤 String Manipulation and Shell Escaping Utilities
int main(int argc, char *argv[])
#define ACDS_MAX_UNIQUE_SESSIONS