11#include "helpers/stringlist.h"
34 if (items != NULL && output != NULL)
37 for (
size_t index = 0; index < items->strings_count; ++index)
50 printf(
" Error! Out of memory condition converting a list of strings to a comma-delimited string in _ListToString()!\n");
72 msg =
"Group does not exist";
76 msg =
"User does not exist";
80 msg =
"Null argument";
84 msg =
"Out of memory";
92 msg =
"Unknown error";
117 prompt =
"Unknown operation";
119 printf(
" Error! %s: %s!\n", prompt, msg);
223 bool canContinue =
false;
236 printf(
" Operation 1: Show all groups\n");
237 printf(
" All groups: %s\n", output.
string);
254 bool canContinue =
false;
267 printf(
" Operation 2: Show all users\n");
268 printf(
" All users : %s\n", output.
string);
285 bool canContinue =
true;
286 const char* userName =
"Arthur";
287 const char* groupName =
"admins";
289 printf(
" Operation 3: Determine if a user is a member of a specific group.\n");
290 printf(
" Is user '%s' in the '%s' group?", userName, groupName);
304 bool canContinue =
false;
307 const char* groupName =
"Users";
310 printf(
" Operation 4: Show all users in a specific group.\n");
318 printf(
" All users in '%s' group: %s\n", groupName, output.
string);
335 bool canContinue =
false;
338 const char* userName =
"Marvin";
341 printf(
" Operation 5: Show all groups containing a specific user.\n");
349 printf(
" All groups with user '%s': %s\n", userName, output.
string);
367 bool canContinue =
false;
370 const char* userName =
"Marvin";
371 const char* groupName =
"Power Users";
374 printf(
" Operation 6: Remove a user from a group.\n");
379 printf(
" Removed user '%s' from group '%s'\n", userName, groupName);
387 printf(
" All groups with user '%s': %s\n", userName, output.
string);
405 bool canContinue =
false;
408 const char* userName =
"Marvin";
409 const char* groupName =
"Users";
412 printf(
" Operation 7: Add a user to a group.\n");
413 printf(
" Adding user '%s' to group '%s'.\n", userName, groupName);
425 printf(
" All groups with user '%s': %s\n", userName, output.
string);
443 bool canContinue =
false;
446 const char* userName =
"Arthur";
449 printf(
" Operation 8: Remove a user from all groups.\n");
457 printf(
" Removing user '%s' from all groups.\n", userName);
458 printf(
" Start: all groups with user '%s': %s\n", userName, output.
string);
461 printf(
" Removing...\n");
473 printf(
" End: all groups with user '%s': %s\n", userName, output.
string);
493 bool canContinue =
false;
497 const char* userName =
"Marvin";
500 printf(
" Operation 9: Remove a user (also removes the user from all groups).\n");
501 printf(
" Removing user '%s'.\n", userName);
513 printf(
" All users : %s\n", output.
string);
526 for (
size_t index = 0; index < groupNames.strings_count; index++)
528 const char* name = groupNames.strings[index];
536 printf(
" Users in group '%s': %s\n", name, output.
string);
579 printf(
"\nMediator Exercise\n");
void DynamicString_Clear(DynamicString *string)
Clear a DynamicString object, releasing any allocated memory. Resets to an empty string.
bool DynamicString_Append(DynamicString *string, const char *s)
Append the specified string to the DynamicString object.
Declaration of the DynamicString structure and supporting functions to work with dynamic strings.
std::vector< std::string > StringList
Typedef for a vector of std::string.
void StringList_Clear(StringList *stringList)
Clear the specified string list. All strings in the list are released. The string list can then be us...
Represents a string that can be grown dynamically.
char * string
The string that can grow.