Skip to content

Instantly share code, notes, and snippets.

@apfohl
Created March 6, 2015 12:28
Show Gist options
  • Select an option

  • Save apfohl/5546a5e7dda70017d933 to your computer and use it in GitHub Desktop.

Select an option

Save apfohl/5546a5e7dda70017d933 to your computer and use it in GitHub Desktop.
astyle example
/* astyle --style=kr --indent=spaces=4 --indent-switches --pad-oper --pad-header --align-pointer=name --add-brackets -n main.c
* astyle -A3s4SpHk3jn main.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
enum state {
NONE = 1,
OK,
ERROR
};
struct state_machine {
enum state state;
enum state last_state;
char *ptr[];
};
int main(int argc, const char **argv)
{
struct state_machine *state_machine = malloc(sizeof(struct state_machine) + argc * sizeof(char *));
if (!state_machine) {
perror("malloc");
return EXIT_FAILURE;
} else {
state_machine->state = NONE;
state_machine->last_state = NONE;
}
for (int i = 0; i < argc; i++) {
printf("%s\n", argv[i]);
state_machine->ptr[i] = strdup(argv[i]);
state_machine->last_state = state_machine->state;
state_machine->state = OK;
}
int j = 0;
do {
switch (state_machine->state) {
case OK:
break;
case ERROR:
break;
default:
break;
}
j++;
} while (j < argc);
int k = 0;
while (k < argc) {
free(state_machine->ptr[k]);
k++;
}
free(state_machine);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment