#include #include #include #include #include void cd(void); void check_defaults(); void clean_filename(); void do_switch(void); void get_number(int *); void get_string(char *); void get_extra(void); void get_nam(void); void get_question(void); void get_yn(void); void make_optstringx(void); void no(void); char *result,*r,*x,*y; char astring[1024],ch,checkradio[20]=""; char defaultmlsdata[120]="",defaultsuccess[120]="",defaultsmtp[80]=""; char defaulttoname[80]="",defaulttoemail[80]="",desstring[120]=""; char field[20]="",filenamehtm[80],filenamemls[80],filenametxt[80],filename[25]=""; char left[120],log[2048]; char msg_chk_end[]="
\n\n"; char msg_chk_str[]=""; char nam[60],optstringx[120],optstringy[120],optstring[120]; char p=' ',qnumstring[20],questring[512]="",required[4096]=" "; char table[] = ""; char titlestring[120]="",type=' ',value[100],xstring[120],yn=' '; int col=0,i,num=0,qnum=1,row=0,tnum,ttnum,useremail_flag=0,username_flag=0; unsigned int j; FILE *fp1,*fp2,*fp3; void main() { clrscr(); // This is a simple way to use the same source with compilers // Borland C++ Version 3.1 uses a 2 byte int size and doesn't support long file names // Borland C++ Builder 5 uses a 4 byte int size and does support long file names i=sizeof(i); if (i==2) printf("Filename must be 8 characters or less, no spaces\n"); else printf("Filename must not contain any spaces\n"); printf("Enter Name of Form to Create->"); get_string(filename); clean_filename(); strcpy(filenamehtm,filename); strcpy(filenametxt,filename); strcpy(filenamemls,filename); strcat(filenamehtm,".htm"); strcat(filenametxt,".txt"); strcat(filenamemls,".mls"); fp1=fopen(filenamehtm,"r"); if (fp1!=NULL) { printf("Sorry, File with that name already exists\nPress Enter to Continue"); getch(); exit(1); } fclose(fp1); check_defaults(); strcpy(log,"LOG: \t\t\"["); strcat(log,filename); strcat(log,"] "); fp1=fopen(filenamehtm,"w"); fp3=fopen("body.$$$","w"); fprintf(fp1,"\n"); printf("Enter Title for Form->"); get_string(titlestring); fprintf(fp1,"%s\n",titlestring); fprintf(fp1,"
\n"); fprintf(fp1,"%s
\n", titlestring); printf("Description->"); get_string(desstring); fprintf(fp1,"%s

\n
\n%s\n
\n",desstring,table); fprintf(fp1,"
\n"); fprintf(fp1,"\n",filename); fprintf(fp1,"\n"); get_extra(); clrscr(); printf("This will add a prompt for User Name as a Required Field\n"); printf("Do you wish to ask for user Name "); get_yn(); if (yn=='Y') { fprintf(fp1,"Enter Your Name
\n"); fprintf(fp1,"

\n"); fprintf(fp3,"UserName\n{Config.UserName}\n"); strcat(log,"[{Config.UserName}]"); username_flag = 1; strcat(required,", "); strcat(required,"UserName"); } printf("This will request a valid Email address as a Required Field\n"); printf("Additionally, it will check the format of what is entered\n"); printf("Do you wish to ask for user email "); get_yn(); if (yn=='Y') { fprintf(fp1,"Enter Your Email address
\n"); fprintf(fp1,"

\n"); fprintf(fp3,"UserEmail\n{Config.UserEmail}\n"); strcat(log,"[{Config.UserEmail}]"); useremail_flag = 1; strcat(required,", "); strcat(required,"UserEmail"); } clrscr(); printf("Questions are auto numbered, so you only need to enter question\n"); printf("To add non question material enter a ~\n"); printf("Enter Question Title->"); get_string(questring); do { clrscr(); if (questring[0]!='~') get_question(); else get_extra(); clrscr(); printf("%s%s%s%s", "Questions are auto numbered, so you only need to enter question\n", "Just Press Enter when Finished with Questions\n", "To add none question material enter a ~\n", "Enter Question Title->"); get_string(questring); } while (strlen(questring)!=0); fprintf(fp1,"\n"); fprintf(fp1,"\n"); fprintf(fp1,"
\n"); fclose(fp1); fclose(fp3); // part2: fp2=fopen(filenametxt,"w"); printf("LOG ALL (Output data to log file) "); get_yn(); if (yn=='Y') fprintf(fp2,"%s\"\n",log); printf("Example: http://guam.packet.org/good.htm\n"); if (strlen(defaultsuccess)>0) printf("Your current default is:\%s\nPressing Enter will use default\n",defaultsuccess); printf("Enter the URL of the web page that the user will\ngo to after successfully submitting this form->"); get_string(astring); if (strlen(astring)<1) strcpy(astring,defaultsuccess); fprintf(fp2,"SUCCESSFUL: \t\"%s\"",astring); clrscr(); //Strip leading blanks and first , strcpy(required,&required[3]); //'Required fields are required to be entered fprintf(fp2,"\nREQUIRED:\t\"%s\"\n",required); printf("This is the SMTP (Simple Mail Transport Protocol) Server that\n"); printf("Processes the mail. Example: guam.packet.org\n"); if (strlen(defaultsmtp)>0) printf("Your current default is:\%s\nPressing Enter will use default\n",defaultsmtp); printf("Enter the SMTP Server to Use->"); get_string(astring); if (strlen(astring)<1) strcpy(astring,defaultsmtp); fprintf(fp2,"SERVER: \t\"%s\"\n",astring); clrscr(); printf("The Name of the person or group to send mail to: John Doe\n"); if (strlen(defaulttoname)>0) printf("Your current default is:\%s\nPressing Enter will use default\n",defaulttoname); printf("Enter the TO: Email Name->"); get_string(astring); if (strlen(astring)<1) strcpy(astring,defaulttoname); fprintf(fp2,"TONAME: \t\"%s\"\n",astring); printf("The Email address of the person or group to send mail to:\n"); printf("johndoe@guam.packet.org\n"); if (strlen(defaulttoemail)>0) printf("Your current default is:\%s\nPressing Enter will use default\n",defaulttoemail); printf("Enter the TOEMAIL address->"); get_string(astring); if (strlen(astring)<1) strcpy(astring,defaulttoemail); fprintf(fp2,"TOEMAIL: \t\"%s\"\n",astring); //If the Name and Email address wasn't asked for as part of the form if (username_flag == 0) { printf("Name to list the mail as coming from\nExample: Anonymous\nEnter the From Email name->"); get_string(astring); fprintf(fp2,"FROMNAME: \t\"%s\"",astring); } else { fprintf(fp2,"FROMNAME: \t\"{Config.Username}\"\n"); } if (useremail_flag == 0) { printf("Email address to list the mail as coming from\nExample: anonymous@guam.packet.org\nEnter the From Email address->"); get_string(astring); fprintf(fp2,"FROMEMAIL: \t\"%s\"\n",astring); } else { fprintf(fp2,"FROMEMAIL: \t\"{Config.Useremail}\""); } fprintf(fp2,"\nSUBJECT: \t\"%s\"\n",titlestring); fprintf(fp2,"BODY: \t\t\"\n"); fp3=fopen("body.$$$","r"); do { ch = fgetc(fp3); if (ch != EOF) putc(ch,fp1); } while (ch != EOF); fprintf(fp2,"\"\n"); fclose(fp2); fclose(fp3); // part3: fp1=fopen(filenamehtm,"r"); fp2=fopen(filenamemls,"w"); fprintf(fp2,"\n"); do { fgets(astring,sizeof(astring),fp1); fprintf(fp2,"%s",astring); } while (strcmp(astring,"
\n")!=0); fprintf(fp2,"\n\n\n%s\n",table); fprintf(fp2,"%sThere has been an error sending the message!\n%s",msg_chk_str,msg_chk_end); if (username_flag == 1) { fprintf(fp2,"\n\n\n\n%s\n", table); fprintf(fp2,"%sYou must enter a name\n%s",msg_chk_str,msg_chk_end); } if (useremail_flag == 1) { fprintf(fp2,"\n\n\n\n%s\n",table); fprintf(fp2,"%sYou must enter an email address%s",msg_chk_str,msg_chk_end); fprintf(fp2,"\n\n\n\n%s\n",table); fprintf(fp2,"%sThe email address you've entered does not appear to be valid!\n%s",msg_chk_str,msg_chk_end); } r=required; do { i=sscanf(r,"%s",field); if (i>0) { if (field[0]=='Q') no(); r=strstr(r+1," "); } } while (r!=NULL); fprintf(fp2,"\n\n\n\n"); result=fgets(astring,sizeof(astring),fp1); do { if (strcmp(astring,"\n")==0) { fprintf(fp2,"\n\n\n\n\n%s\n",table); fprintf(fp2,"{System.Version}\n%s",msg_chk_end); strcpy(astring,"\n"); } // ROUTINE FOR A TEXT OPTIONS x=strstr(astring,"TYPE=TEXT"); if (x!=NULL) { get_nam(); x=strstr(astring,"VALUE="); x=x+7; strncpy(left,astring,x-astring); left[x-astring]=NULL; strcpy(xstring,x); sprintf(astring,"%s{CONFIG.%s}%s",left,nam,xstring); } // ROUTINE FOR B TEXTARE OPTIONS x=strstr(astring,"%s",nam,value,value,xstring); } fprintf(fp2,"%s",astring); result=fgets(astring,sizeof(astring),fp1); } while (result!=NULL); fclose(fp2); fclose(fp1); clrscr(); printf("You have now finished creating your form\n"); printf("The following three files have been created\n\t%s\n\t%s\n\t%s\n", filenamehtm,filenamemls,filenametxt); printf("%s%s%s%s%s", "The htm file can be placed in your regular web directory\n", "The txt file needs to be placed in the \\cgi-bin\\mlsdata directory\n", "The mls file needs to be placed in the \\cgi-bin\\mlddata directory\n\tand renamed to htm\n", "\nIf your AnalogX root directory is \\www the following batch commands would work\n", "\n\tBatch file mlstxt.bat\n\tcopy %%1.txt \\www\\cgi-bin\\mlsdata\\%%1.txt\n\tcopy %%1.mls \\www\\cgi-bin\\mlsdata\\%%1.htm\n\n\n"); if (strlen(defaultmlsdata)>1) { printf("You have a default directory defined\ndo you want to copy %s and %s to %s\n", filenamemls,filenametxt,defaultmlsdata); get_yn(); if (yn=='Y') { fp1=fopen(filenamemls,"r"); clrscr(); printf("\nCopying %s to ",filenamemls); strcpy(filenamemls,defaultmlsdata); strcat(filenamemls,filenamehtm); fp2=fopen(filenamemls,"w"); printf("%s\n",filenamemls); while (!feof(fp1)) { ch=fgetc(fp1); if (!feof(fp1)) fputc(ch, fp2); } fclose(fp1); fclose(fp2); fp1=fopen(filenametxt,"r"); printf("\n\nCopying %s to ",filenametxt); strcpy(filenamemls,defaultmlsdata); strcat(filenamemls,filenametxt); fp2=fopen(filenamemls,"w"); printf("%s\n",filenamemls); while (!feof(fp1)) { ch=fgetc(fp1); if (!feof(fp1)) fputc(ch, fp2); } fclose(fp1); fclose(fp2); } } } void cd() { num = 0; do { printf("\nNumber of %s Options",checkradio); get_number(&num); } while (num==0); printf("Put %s Box in Table? Enter 0 for one or number of columns",checkradio); get_number(&tnum); if (tnum > 0) fprintf(fp1,"%s\n",table); ttnum = 0; printf("If you enter Other as the last option a text field will be added\n"); for(i=1;i<=num;i++) { printf("Enter Option (%d)->",i); get_string(optstring); make_optstringx(); if(type=='C') fprintf(fp1,"\n",checkradio,qnum-1,64+i,optstringx); else fprintf(fp1,"\n",checkradio,qnum-1,optstringx); fprintf(fp1,"%s\n",optstring); strcpy(optstringy,optstring); if (type=='C') { fprintf(fp3,"%c:{Config.Q%d%c}\n",64+i,qnum-1,64+i); strcat(log,"[{Config.Q"); itoa(qnum-1,qnumstring,10); strcat(log,qnumstring); sprintf(qnumstring,"%c",64+i); strcat(log,qnumstring); strcat(log,"}]"); } if (type=='D' && i==1) { fprintf(fp3,"{Config.Q%d}\n",qnum-1); strcat(log,"[{Config.Q"); itoa(qnum-1,qnumstring,10); strcat(log,qnumstring); strcat(log,"}]"); } for(j=0;j\n",qnum-1); fprintf(fp3,"OTHER:{Config.Q%dOTHER}\n",qnum-1); strcat(log,"[{Config.Q"); itoa(qnum-1,qnumstring,10); strcat(log,qnumstring); strcat(log,"OTHER"); strcat(log,"}]"); } if (tnum == 0) fprintf(fp1,"
\n"); if (tnum > 0) { fprintf(fp1,"\n"); ttnum++; if (ttnum==tnum) { fprintf(fp1,"\n"); ttnum = 0; } if ((i + 1) < num) fprintf(fp1,"\n"); if ((i + 1) == num) fprintf(fp1,"\n",tnum - ttnum); } } if (tnum > 0) fprintf(fp1,"\n"); } void get_extra() { clrscr(); printf("%s%s%s%s%s", "You can enter plain text lines or HTML Codes\n(Such as Instructions)\n", "Some Sample Code text to bold some text\ntext to Italic text\n", "
text
to Center Text\n
for a Horizontal line\n", "An image link could also be added\n\n", "Enter the text you wish to add, Just press enter when done.\n"); if (strlen(questring)<1) { printf("Add Additional Text after title and description\n"); printf("and before asking for the name or first question\n"); strcpy(questring,"~"); } do { get_string(questring); fprintf(fp1,"%s
\n",questring); } while (strlen(questring)>0); } void no() { if(field[strlen(field)-1]==',') field[strlen(field)-1]=NULL; fprintf(fp2,"\n\n\n\n%s\n",field,table); fprintf(fp2,"%sYou must enter \"%s\"\n%s",msg_chk_str,field,msg_chk_end); } void do_switch() { switch(type) { case 'A' : col = 0; do { printf("This is the number of Characters\nENTER SIZE OF COLUMN"); get_number(&col); } while (col==0); fprintf(fp1,"\n",qnum-1,col); fprintf(fp3,"{Config.Q%d}\n",qnum-1); strcat(log,"[{Config.Q"); itoa(qnum-1,qnumstring,10); strcat(log,qnumstring); strcat(log,"}]"); break; case 'B' : col = 0; do { printf("This is the number of Characters\nENTER SIZE OF COLUMNS"); get_number(&col); } while (col==0); row = 0; do { printf("This is the number of Lines\nENTER SIZE OF ROWS"); get_number(&row); } while (row==0); fprintf(fp1,"\n",qnum-1,col,row); fprintf(fp3,"{Config.Q%d}\n",qnum-1); strcat(log,"[{Config.Q"); itoa(qnum-1,qnumstring,10); strcat(log,qnumstring); strcat(log,"}]"); break; case 'C' : strcpy(checkradio,"CHECKBOX"); cd(); break; case 'D' : strcpy(checkradio,"RADIO"); cd(); break; case 'E' : fprintf(fp1,"\n"); break; } } void check_defaults() { fp1=fopen("defaults","r"); if (fp1!=NULL) { fgets(defaultsuccess,120,fp1); defaultsuccess[strlen(defaultsuccess)-1]=NULL; fgets(defaultsmtp,80,fp1); defaultsmtp[strlen(defaultsmtp)-1]=NULL; fgets(defaulttoname,80,fp1); defaulttoname[strlen(defaulttoname)-1]=NULL; fgets(defaulttoemail,80,fp1); defaulttoemail[strlen(defaulttoemail)-1]=NULL; fgets(defaultmlsdata,120,fp1); defaultmlsdata[strlen(defaultmlsdata)-1]=NULL; fclose(fp1); } else { clrscr(); fp1=fopen("defaults","w"); printf("\nYou don't currently have a defaults file\n"); printf("Enter the default URL for a successfull process\n"); get_string(defaultsuccess); printf("Enter the default smtp server\n"); get_string(defaultsmtp); printf("Enter the default to name\n"); get_string(defaulttoname); printf("Enter the default to email\n"); get_string(defaulttoemail); printf("Enter the full path to the mlsdata dirctory including \\\n"); printf("Example:\n\tc:\\www\\cgi-bin\\mlsdata\\\n"); get_string(defaultmlsdata); fprintf(fp1,"%s\n%s\n%s\n%s\n%s\n", defaultsuccess,defaultsmtp,defaulttoname,defaulttoemail,defaultmlsdata); fclose(fp1); clrscr(); } } void get_string(char *p) { fflush(stdin); gets(p); } void get_number(int *getnum) { char temp_string[20]=""; do { printf("->"); get_string(temp_string); } while(!isdigit(temp_string[0])); sscanf(temp_string,"%d",getnum); } void get_question() { printf("%s\n",questring); fprintf(fp1,"Question %d\n",qnum); printf("\nCurrently this doesn't work for checkboxes\n"); printf("Is this a required question "); get_yn(); if (yn=='Y') { strcat(required,", Q"); itoa(qnum,qnumstring,10); strcat(required,qnumstring); } qnum++; fprintf(fp1,"%s\n",questring); fprintf(fp3,"[%s] \n",questring); fprintf(fp1,"
\n"); printf("%s%s%s%s%s%s", "Select Type of Question\n", "A - Text (Single Line)\n", "B - Text Area (Multi-Line)\n", "C - Check Box (Multi-Check option)\n", "D - Radio Button (Single Check)\n", "E - Selection\n"); type=' '; do { type = toupper(getc(stdin)); } while (type!='A' && type!='B' && type!='C' && type!='D' && type!='E'); do_switch(); fprintf(fp1,"

\n"); } void get_yn() { do { printf("(Y or N)->"); yn=toupper(getc(stdin)); } while (yn!='Y' && yn!='N'); printf("\n"); } void get_nam() { x=strstr(astring,"NAME="); x=x+5; y=strstr(x," "); strncpy(nam,x,y-x); nam[y-x]=NULL; } void make_optstringx() { strcpy(optstringx,""); x=optstringx; for (j=0;j