summaryrefslogtreecommitdiff
path: root/src/tool/adduser.c
diff options
context:
space:
mode:
authorChuck Miller <shadowmil@gmail.com>2009-12-25 05:00:31 -0500
committerJared Adams <jaxad0127@gmail.com>2009-12-26 00:40:11 -0700
commit634aeeb9d58b01f9de6632a014a063ef0c4cf31e (patch)
tree70023dd2bcc12a3f96ec6f118d80e27411920531 /src/tool/adduser.c
parent113fcc4f0a7a0921e94bc415515dd4b393a29d60 (diff)
downloadtmwa-634aeeb9d58b01f9de6632a014a063ef0c4cf31e.tar.gz
tmwa-634aeeb9d58b01f9de6632a014a063ef0c4cf31e.tar.bz2
tmwa-634aeeb9d58b01f9de6632a014a063ef0c4cf31e.tar.xz
tmwa-634aeeb9d58b01f9de6632a014a063ef0c4cf31e.zip
Used the "indent" C formatting program from GNU to do some clean ups
The command options used was: -nbad -bap -sc -bl -blf -bli0 -cli4 -cbi0 -di5 -nbc -bls -ip2 -nut -ts4 -bap -i4 -sob -npsl
Diffstat (limited to 'src/tool/adduser.c')
-rw-r--r--src/tool/adduser.c177
1 files changed, 98 insertions, 79 deletions
diff --git a/src/tool/adduser.c b/src/tool/adduser.c
index e22e7e9..6ebbdf1 100644
--- a/src/tool/adduser.c
+++ b/src/tool/adduser.c
@@ -12,85 +12,104 @@ char *account_txt = "../save/account.txt";
//-----------------------------------------------------
// Function to suppress control characters in a string.
//-----------------------------------------------------
-int remove_control_chars(unsigned char *str) {
- int i;
- int change = 0;
-
- for(i = 0; str[i]; i++) {
- if (str[i] < 32) {
- str[i] = '_';
- change = 1;
- }
- }
-
- return change;
+int remove_control_chars (unsigned char *str)
+{
+ int i;
+ int change = 0;
+
+ for (i = 0; str[i]; i++)
+ {
+ if (str[i] < 32)
+ {
+ str[i] = '_';
+ change = 1;
+ }
+ }
+
+ return change;
}
-int main(int argc, char *argv[]) {
-
- char username[24];
- char password[24];
- char sex[2];
-
- int next_id, id;
- char line[1024];
-
- // Check to see if account.txt exists.
- printf("Checking if '%s' file exists...\n", account_txt);
- FILE *FPaccin = fopen_(account_txt, "r");
- if (FPaccin == NULL) {
- printf("'%s' file not found!\n", account_txt);
- printf("Run the setup wizard please.\n");
- exit(0);
- }
-
- next_id = 2000000;
- while(fgets(line, sizeof(line)-1, FPaccin)) {
- if (line[0] == '/' && line[1] == '/') { continue; }
- if (sscanf(line, "%d\t%%newid%%\n", &id) == 1) {
- if (next_id < id) {
- next_id = id;
- }
- } else {
- sscanf(line,"%i%[^ ]", &id);
- if (next_id <= id) {
- next_id = id +1;
- }
- }
- }
- close(FPaccin);
- printf("File exists.\n");
-
- printf("Don't create an account if the login-server is online!!!\n");
- printf("If the login-server is online, press ctrl+C now to stop this software.\n");
- printf("\n");
-
- strcpy(username, "");
- while (strlen(username) < 4 || strlen(username) > 23) {
- printf("Enter an username (4-23 characters): ");
- scanf("%s", &username);
- username[23] = 0;
- remove_control_chars(username);
- }
-
- strcpy(password, "");
- while (strlen(password) < 4 || strlen(password) > 23) {
- printf("Enter a password (4-23 characters): ");
- scanf("%s", &password);
- password[23] = 0;
- remove_control_chars(password);
- }
-
- strcpy(sex, "");
- while (strcmp(sex, "F") != 0 && strcmp(sex, "M") != 0) {
- printf("Enter a gender (M for male, F for female): ");
- scanf("%s", &sex);
- }
-
- FILE *FPaccout = fopen_(account_txt, "r+");
- fseek(FPaccout, 0, SEEK_END);
- fprintf(FPaccout, "%i %s %s - %s -\r\n", next_id, username, password, sex);
- close(FPaccout);
-
- printf("Account added.\n");
+int main (int argc, char *argv[])
+{
+
+ char username[24];
+ char password[24];
+ char sex[2];
+
+ int next_id, id;
+ char line[1024];
+
+ // Check to see if account.txt exists.
+ printf ("Checking if '%s' file exists...\n", account_txt);
+ FILE *FPaccin = fopen_ (account_txt, "r");
+ if (FPaccin == NULL)
+ {
+ printf ("'%s' file not found!\n", account_txt);
+ printf ("Run the setup wizard please.\n");
+ exit (0);
+ }
+
+ next_id = 2000000;
+ while (fgets (line, sizeof (line) - 1, FPaccin))
+ {
+ if (line[0] == '/' && line[1] == '/')
+ {
+ continue;
+ }
+ if (sscanf (line, "%d\t%%newid%%\n", &id) == 1)
+ {
+ if (next_id < id)
+ {
+ next_id = id;
+ }
+ }
+ else
+ {
+ sscanf (line, "%i%[^ ]", &id);
+ if (next_id <= id)
+ {
+ next_id = id + 1;
+ }
+ }
+ }
+ close (FPaccin);
+ printf ("File exists.\n");
+
+ printf ("Don't create an account if the login-server is online!!!\n");
+ printf
+ ("If the login-server is online, press ctrl+C now to stop this software.\n");
+ printf ("\n");
+
+ strcpy (username, "");
+ while (strlen (username) < 4 || strlen (username) > 23)
+ {
+ printf ("Enter an username (4-23 characters): ");
+ scanf ("%s", &username);
+ username[23] = 0;
+ remove_control_chars (username);
+ }
+
+ strcpy (password, "");
+ while (strlen (password) < 4 || strlen (password) > 23)
+ {
+ printf ("Enter a password (4-23 characters): ");
+ scanf ("%s", &password);
+ password[23] = 0;
+ remove_control_chars (password);
+ }
+
+ strcpy (sex, "");
+ while (strcmp (sex, "F") != 0 && strcmp (sex, "M") != 0)
+ {
+ printf ("Enter a gender (M for male, F for female): ");
+ scanf ("%s", &sex);
+ }
+
+ FILE *FPaccout = fopen_ (account_txt, "r+");
+ fseek (FPaccout, 0, SEEK_END);
+ fprintf (FPaccout, "%i %s %s - %s -\r\n", next_id, username,
+ password, sex);
+ close (FPaccout);
+
+ printf ("Account added.\n");
}