/********************PicLink 1.0 By Chris Murray********************* This program creates a multitude of HTML files each of which displays a picture, and each of which is linked to other views. This is to create a virtual tour of still photos, allowing the viewer to look in different directions from a certain vantage point, and move forward from point to point. One of the many files put out by this program is listed below: TuHS Tour View 001E
Location 001 looking East
Go:  Forward     To Main Map
Turn:  Left   Around    Right
The program creates the links from a simpler expression of the connectivity encoded in a text file that the program reads. A Sample file is listed below: (the comments are indicated by <-- and are not in the real version of the file :- ) 001N. <-- Just a view. location 001, looking North. 001 can be any text. 001E-018E. <-- from location 001 looking East, the forward link is to 018 East 001S-004S. 001W. 004N-001N. ! this is a legal comment (! must be in the first column) 004E. 004S-006S. <-- and so on and so forth 004W. 006N-004N. 006E. 006S-007S.B <--This HTML file has its body in a separate file B006S.HTM 006W. 007N-006N. 007E. 007W-003N. 007S-008S. 008N-007N.M <--This HTML file has an image map in file M008N.HTM 008E-009E. 008S. 008W. 018E-002E. 018W-001W. 018S. 018N-019N. 002E-012E. 012E-003E. 003N. <--locations need not be entered in order. 003E. 003S. 003W. . <--End of file marker. the periods are obligatory, and all <--syntax is checked before the program proceeds with anything. *********************************************************************/ #include #include //#include //#include //#include #include //#include #define TRUE 1 #define FALSE 0 #define MAXBUFF 200 int main(void) { int errors,hasmap,hasbody; char iline[80]; //holds the input line char ffile[20],bfile[20],mfile[20]; char lloc[10]; char larray[MAXBUFF][5][11]; //stores and organizes the input //larray[Location][Direction][Character] char *dataleft; int dptr,cptr,maxptr,serrors,c,i,j,k,found; int lleft, rright, aaround; FILE *handle,*handle2; clrscr(); for (i=0; i<=MAXBUFF; ++i) // this clears the storage array { for (j=0; j<=4; ++j) { for (k=0; k<=10; ++k) { larray[i][j][k] = 0; }; }; }; printf("Piclink 1.0\n\n"); printf("\nPlease enter the name of the input file> "); //open the input file scanf("%s",&ffile); printf("Reading from file %s\n",ffile); if((handle = fopen(ffile,"r")) == NULL) //If there were errors opening file { printf("Cannot open input file\npress any key to exit..."); getch(); exit(0); }; dataleft = ffile; serrors = FALSE; maxptr = -1; do { dataleft = fgets(iline,80,handle); //read in a line if ((iline[0] != '!') && (iline[0] != '.') && *dataleft) // if not end of file { switch(iline[3]) //This would be the direction column { case 'N': {dptr = 1; break;}; //It should be N,S,E or W case 'E': {dptr = 2; break;}; case 'S': {dptr = 3; break;}; case 'W': {dptr = 4; break;}; default : { serrors = TRUE; //spaz if it isn't printf("\nError in first direction column\n"); printf("%s\n",iline); printf(" ^ - should be N,E,S, or W\n\n"); }; }; /*end switch */ if (iline[4] == '-') /* if there is a link field */ { switch(iline[8]) //This is the direction column of the linked location { case 'N': { break;}; //It should be N,S,E or W case 'E': { break;}; case 'S': { break;}; case 'W': { break;}; default : { serrors = TRUE; printf("\nError in second direction column\n"); printf("%s\n",iline); printf(" ^ - should be N,E,S, or W\n\n"); }; }; if (iline[9] != '.') //Make sure they end with a period { serrors = TRUE; printf("\nMissing period\n"); printf("%s",iline); printf("\n ^\n\n"); }; } else if (iline[4] == '.') {} //If it not linked it should end with a period else { serrors = TRUE; //otherwise spaz out printf("\nMissing period\n"); printf("%s\n",iline); printf(" ^\n\n"); }; if (!serrors) //If there haven't been any errors { printf("."); cptr = 0; found = FALSE; while ((!found) && (cptr <= maxptr)) { // Search the storage array to see if there is another // record with the same direction // If there is a match in the first direction field store the line if ((iline[0] == larray[cptr][0][0]) && (iline[1] == larray[cptr][0][1]) && (iline[2] == larray[cptr][0][2])) { i=0; while (iline[i]) { larray[cptr][dptr][i] = iline[i]; //store the input line i++; found = TRUE; }; }; cptr++; }; if (!found) //if you can't find a place for it, make one { maxptr++; if (maxptr == MAXBUFF) //making sure the array doesn't blow up { printf("Array overload press any key to exit"); getch(); exit(0); }; for(i=0; i<=2; i++) larray[maxptr][0][i] = iline[i]; i=0; while (iline[i]) { larray[maxptr][dptr][i] = iline[i]; //copy the input line i++; }; }; }; }; /* end if (iline[0] != '.') */ } while ((iline[0] != '.') && (dataleft)); //input do loop fclose(handle); //close the input file if (serrors) //if there were errors, don't go on { printf("There were errors in the input file\n"); printf("Press any key to exit\n"); getch(); exit(0); }; printf("\nInput file read with no errors - Proceeding\nPress q to quit or any other key to continue\n"); c = getch(); if((c == 'q') || (c == 'Q')) exit(0); printf("Now writing files %d\n",maxptr); for (i=0; i<=19; i++) ffile[i] = 0; //clear the file name buffer ffile[0] = 'L'; //Set up the output file string ffile[5] = '.'; ffile[6] = 'H'; ffile[7] = 'T'; ffile[8] = 'M'; bfile[0] = 'B'; //Set up the Body file string bfile[5] = '.'; bfile[6] = 'H'; bfile[7] = 'T'; bfile[8] = 'M'; mfile[0] = 'M'; //Set up the Map file string mfile[5] = '.'; mfile[6] = 'H'; mfile[7] = 'T'; mfile[8] = 'M'; for (cptr = 0; cptr <= maxptr; cptr++) //go through the input array { for (dptr = 1; dptr <= 4; dptr++) { if (larray[cptr][dptr][0]) //if there is a view in that direction at that location { j = 0; hasmap = FALSE; hasbody = FALSE; while(larray[cptr][dptr][j++] != '.'); //Find the location of the body or map flag. if (larray[cptr][dptr][j] == 'M') //If there is a map file { printf("Map: "); hasmap = TRUE; for (i = 0; i <=3; i++) mfile[i+1] = larray[cptr][dptr][i]; }; if (larray[cptr][dptr][j] == 'B') //If there is a body file { printf("Body: "); hasbody = TRUE; for (i = 0; i <=3; i++) bfile[i+1] = larray[cptr][dptr][i]; }; for (i = 0; i <=3; i++) ffile[i+1] = larray[cptr][dptr][i]; printf("writing file %s\n",ffile); handle = fopen(ffile,"w"); switch (larray[cptr][dptr][3]) //Setting up the turn links for the same location { case 'N': {rright = 2; lleft = 4; aaround = 3; break;}; case 'E': {rright = 3; lleft = 1; aaround = 4; break;}; case 'S': {rright = 4; lleft = 2; aaround = 1; break;}; case 'W': {rright = 1; lleft = 3; aaround = 2; break;}; }; /*******************************************************/ /* Writing HTML file */ /*******************************************************/ fprintf(handle,"\n"); fprintf(handle,"\n"); fprintf(handle," TuHS Tour View "); for (i = 0; i<= 3; i++) fprintf(handle, "%c",larray[cptr][dptr][i]); fprintf(handle,"\n"); fprintf(handle,"\n"); fprintf(handle," \n"); if (hasmap) //If there is an associated map file { if((handle2 = fopen(mfile,"r")) == NULL) //If there were errors opening file { printf(" Cannot open map file %s\n",mfile); }; while(*fgets(iline,80,handle2)) fprintf(handle,"%s",iline); //Dump the contents of the map file here fclose(handle2); //Close the map file }; fprintf(handle,"
\n"); fprintf(handle,"\n"); fprintf(handle,"Location "); for (i = 0; i<= 2; i++) fprintf(handle, "%c",larray[cptr][dptr][i]); fprintf(handle," looking "); switch (larray[cptr][dptr][3]) { case 'N': {fprintf(handle,"North"); break;}; case 'E': {fprintf(handle,"East"); break;}; case 'S': {fprintf(handle,"South"); break;}; case 'W': {fprintf(handle,"West"); break;}; }; fprintf(handle,"\n
\n"); fprintf(handle,"
\n"); fprintf(handle,"
\n"); fprintf(handle,"Go: \n"); if (larray[cptr][dptr][4] == '-') { fprintf(handle,"Forward    \n"); }; fprintf(handle,"To Main Map\n"); fprintf(handle,"
\n"); fprintf(handle,"Turn: \n"); if (larray[cptr][lleft][0]) //if you can turn left { fprintf(handle,"Left  \n"); }; if (larray[cptr][aaround][0]) //if you can turn around { fprintf(handle,"Around   \n"); }; if (larray[cptr][rright][0]) //if you can turn right { fprintf(handle,"Right\n"); }; fprintf(handle,"
\n"); fprintf(handle,"
\n"); fprintf(handle,"\n"); fprintf(handle,"\n"); /*******************************************************/ /* Done Writing HTML file */ /*******************************************************/ fclose(handle); }; }; }; printf("Done - press any key to continue\n\n"); getch(); };