#include #include #include #include void strtrm (char *string); typedef struct sp_list { char username[80]; struct sp_list *next; }SP_LIST; SP_LIST *userids =0; SP_LIST *wcard =0; int id_count = 0; int w_count = 0; void print_body() { puts(" var number = \"1234567890\";"); puts("var i;"); puts("var len = list.length;"); puts("for(i =0; i0) { if(*buffer == '*') { w_count++; wcard_ptr = (SP_LIST*)malloc(sizeof(SP_LIST)); snprintf(wcard_ptr->username, 50, "%c", buffer[1]); wcard_ptr->next = 0; if(!wcard) wcard = wcard_ptr; else wcard_current->next = wcard_ptr; wcard_current = wcard_ptr; } else { id_count++; userid_ptr = (SP_LIST*)malloc(sizeof(SP_LIST)); strncpy(userid_ptr->username, buffer, 50); userid_ptr->next = 0; if(!userids) userids = userid_ptr; else userid_current->next = userid_ptr; userid_current = userid_ptr; } } } fclose(fp); } void send_list() { SP_LIST *ptr; int i = 1; printf("function is_InList(userid)\n{\n"); printf("var list = new Array ("); for(ptr = userids; ptr; ptr = ptr->next) { if (i < id_count) printf("\"%s\",", ptr->username); else printf("\"%s\"", ptr->username); i++; } printf(");\n"); printf("var anothercase = new Array ("); i = 1; for(ptr = wcard; ptr; ptr = ptr->next) { if (i < w_count) printf("\"%s\",", ptr->username); else printf("\"%s\"", ptr->username); i++; } printf(");\n"); print_body(); } void free_sp_list(SP_LIST *list) { SP_LIST *ptr; while(list) { ptr = list->next; free(list); list = ptr; } } int main() { printf("Content-type: text/javascript\n\n"); read_from_file(); send_list(); free_sp_list(userids); free_sp_list(wcard); return 0; } void strtrm (char *string) { char *ptr; char *newstring; int len; len = strlen (string); newstring = (char *) malloc ((len + 1) * sizeof (char)); if (!newstring) printf("malloc failed"); for (ptr = string; *ptr && isspace (*ptr); ptr++); strncpy (newstring, ptr, len + 1); if (strlen (newstring)) { ptr = strchr (newstring, '\0'); for (ptr--; (ptr >= newstring) && isspace (*ptr); ptr--); *(ptr + 1) = '\0'; } strncpy (string, newstring, len + 1); free (newstring); }