2012-05-02 21:42:03 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2012-05-03 21:36:02 +00:00
|
|
|
#include <stdlib.h>
|
2012-05-02 21:42:03 +00:00
|
|
|
|
2012-05-03 17:40:46 +00:00
|
|
|
static void generate_keyhandler(void) {
|
|
|
|
|
|
|
|
printf("9000 REM ******************\n");
|
2012-05-03 21:36:02 +00:00
|
|
|
printf("9002 REM * GET KEYPRESSES *\n");
|
|
|
|
printf("9004 REM ******************\n");
|
|
|
|
|
|
|
|
printf("9006 N%%=1\n");
|
2012-05-03 17:40:46 +00:00
|
|
|
|
|
|
|
/* memory location -16384 holds keyboard strobe */
|
|
|
|
/* Loop until a key is pressed. */
|
2012-05-03 21:36:02 +00:00
|
|
|
printf("9008 X=PEEK(-16384): IF X < 128 THEN 9008\n");
|
2012-05-03 17:40:46 +00:00
|
|
|
/* get the key value, convert to ASCII */
|
|
|
|
printf("9010 X=PEEK(-16368)-128\n");
|
2012-05-03 21:36:02 +00:00
|
|
|
/* Exit if escape or Q pressed */
|
|
|
|
printf("9020 IF X=27 OR X=81 THEN END\n");
|
2012-05-03 17:40:46 +00:00
|
|
|
/* increment page count if space or -> */
|
2012-05-03 21:36:02 +00:00
|
|
|
printf("9030 IF X=21 OR X=32 THEN P%%=P%%+1:N%%=3\n");
|
2012-05-03 17:40:46 +00:00
|
|
|
/* decrement page count if <- */
|
2012-05-03 21:36:02 +00:00
|
|
|
printf("9040 IF X=8 THEN P%%=P%%-1:N%%=2\n");
|
2012-05-03 17:40:46 +00:00
|
|
|
/* keep from going off the end */
|
|
|
|
printf("9050 IF P%%>TP%% THEN P%%=TP%%\n");
|
|
|
|
printf("9060 IF P%%<0 THEN P%%=0\n");
|
|
|
|
printf("9070 RETURN\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void generate_footer(char *left, char *center, int cols) {
|
2012-05-02 21:42:03 +00:00
|
|
|
|
|
|
|
int center_len,center_count,i,right_count;
|
|
|
|
|
2012-05-03 17:40:46 +00:00
|
|
|
printf("10000 REM ****************\n");
|
|
|
|
printf("10001 REM * PRINT FOOTER *\n");
|
|
|
|
printf("10002 REM ****************\n");
|
2012-05-02 21:42:03 +00:00
|
|
|
/* make text black on white; move to bottom line */
|
2012-05-03 21:36:02 +00:00
|
|
|
printf("10003 HOME: INVERSE : VTAB 24\n");
|
2012-05-02 21:42:03 +00:00
|
|
|
|
2012-05-03 17:40:46 +00:00
|
|
|
printf("10005 X$=STR$(P%%)+\"/\":X$=X$+STR$(TP%%)\n");
|
|
|
|
printf("10007 L%%=LEN(X$)\n");
|
2012-05-02 21:42:03 +00:00
|
|
|
|
2012-05-03 17:40:46 +00:00
|
|
|
printf("10010 PRINT \"%s",left);
|
2012-05-02 21:42:03 +00:00
|
|
|
|
|
|
|
center_len=strlen(center);
|
|
|
|
center_count=(cols-center_len)/2;
|
|
|
|
center_count-=strlen(left);
|
|
|
|
|
|
|
|
if (center_count<0) {
|
|
|
|
fprintf(stderr,"Error! can't fit text in footer\n");
|
|
|
|
center_count=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0;i<center_count;i++) printf(" ");
|
|
|
|
printf("%s\";\n",center);
|
|
|
|
|
|
|
|
right_count=cols-strlen(left)-center_count-center_len;
|
|
|
|
|
2012-05-03 17:40:46 +00:00
|
|
|
printf("10012 FOR I=0 TO %d-L%%:PRINT \" \";: NEXT I\n",right_count-1);
|
2012-05-02 21:42:03 +00:00
|
|
|
|
2012-05-03 17:40:46 +00:00
|
|
|
printf("10014 PRINT LEFT$(X$,L%%-1);\n");
|
2012-05-02 21:42:03 +00:00
|
|
|
|
|
|
|
/* set last character to the right most char of the total pages */
|
|
|
|
/* without scrolling. */
|
2012-05-03 17:40:46 +00:00
|
|
|
printf("10015 TP$=STR$(TP%%) : X$=RIGHT$(TP$,1) : X=VAL(X$): POKE 2039,X+48\n");
|
2012-05-02 21:42:03 +00:00
|
|
|
/* reset text, move cursor up */
|
2012-05-03 17:40:46 +00:00
|
|
|
printf("10020 NORMAL : VTAB 1: PRINT\"\"\n");
|
|
|
|
printf("10030 RETURN\n");
|
2012-05-02 21:42:03 +00:00
|
|
|
}
|
|
|
|
|
2012-05-03 21:36:02 +00:00
|
|
|
static void print_line(unsigned char c, int num) {
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i=0;i<num;i++) printf("%c",c);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void center_comment(unsigned char c, int max_len, char *string) {
|
|
|
|
|
|
|
|
int half_len;
|
|
|
|
|
|
|
|
half_len=(max_len-strlen(string))/2;
|
|
|
|
|
|
|
|
print_line(' ',half_len);
|
|
|
|
printf("%s",string);
|
|
|
|
/* handle strings of odd length */
|
|
|
|
print_line(' ',max_len-half_len-strlen(string));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void generate_initial_comment(char *title, char *author, char *email) {
|
|
|
|
|
|
|
|
int max_len;
|
|
|
|
|
|
|
|
max_len=strlen(title);
|
|
|
|
if (max_len<strlen(author)) max_len=strlen(author);
|
|
|
|
if (max_len<strlen(email)) max_len=strlen(email);
|
|
|
|
|
|
|
|
printf("2 REM ");
|
|
|
|
print_line('*',max_len+4);
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
printf("4 REM * ");
|
|
|
|
center_comment(' ',max_len,title);
|
|
|
|
printf(" *\n");
|
|
|
|
|
|
|
|
printf("6 REM * ");
|
|
|
|
center_comment(' ',max_len,author);
|
|
|
|
printf(" *\n");
|
|
|
|
|
|
|
|
printf("8 REM * ");
|
|
|
|
center_comment(' ',max_len,email);
|
|
|
|
printf(" *\n");
|
|
|
|
|
|
|
|
printf("9 REM ");
|
|
|
|
print_line('*',max_len+4);
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
struct project_info {
|
|
|
|
char *title;
|
|
|
|
char *author;
|
|
|
|
char *email;
|
|
|
|
int slides;
|
|
|
|
};
|
2012-05-02 21:42:03 +00:00
|
|
|
|
2012-05-04 20:55:31 +00:00
|
|
|
struct footer_info {
|
|
|
|
char *left;
|
|
|
|
char *center;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define SLIDE_40COL 0
|
|
|
|
#define SLIDE_80COL 1
|
|
|
|
#define SLIDE_HGR 2
|
|
|
|
#define SLIDE_HGR2 3
|
|
|
|
|
|
|
|
#define MAX_SLIDES 100
|
|
|
|
|
|
|
|
struct slide_info {
|
|
|
|
int type;
|
|
|
|
char *filename;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define LINES_PER_SLIDE 25
|
|
|
|
|
|
|
|
static void generate_slide(int num, int max, char*filename) {
|
|
|
|
|
|
|
|
int line_num;
|
|
|
|
|
|
|
|
/* line numbers start at 100 and run LINES_PER_SLIDE per slide */
|
|
|
|
line_num=100+(num*LINES_PER_SLIDE);
|
|
|
|
|
|
|
|
printf("%d REM ",line_num); line_num++;
|
|
|
|
print_line('*',strlen(filename)+8);
|
|
|
|
printf("\n");
|
|
|
|
printf("%d REM *** %s ***\n",line_num,filename); line_num++;
|
|
|
|
printf("%d REM ",line_num); line_num++;
|
|
|
|
print_line('*',strlen(filename)+8);
|
|
|
|
printf("\n");
|
|
|
|
printf("%d GOSUB 10000\n",line_num); line_num++;
|
|
|
|
printf("%d VTAB 1: PRINT \" RAPL %d\"\n",line_num,num); line_num++;
|
|
|
|
printf("%d PRINT\n",line_num); line_num++;
|
|
|
|
printf("%d PRINT \"* RAPL is awesome\"\n",line_num); line_num++;
|
|
|
|
printf("%d GOSUB 9000\n",line_num); line_num++;
|
|
|
|
printf("%d ON N%% GOTO %d,%d,%d\n",
|
|
|
|
line_num,
|
|
|
|
/* previous */
|
|
|
|
num==0?(100+(num*LINES_PER_SLIDE)):(100+((num-1)*LINES_PER_SLIDE)),
|
|
|
|
/* current */
|
|
|
|
100+(num*LINES_PER_SLIDE),
|
|
|
|
/* next */
|
|
|
|
num<(max-1)?(100+((num+1)*LINES_PER_SLIDE)):
|
|
|
|
(100+(num*LINES_PER_SLIDE)));
|
|
|
|
}
|
|
|
|
|
2012-05-02 21:42:03 +00:00
|
|
|
int main(int argc, char **argv) {
|
|
|
|
|
2012-05-04 20:55:31 +00:00
|
|
|
int i;
|
2012-05-03 21:36:02 +00:00
|
|
|
char project_directory[BUFSIZ];
|
|
|
|
char filename[BUFSIZ],string[BUFSIZ];
|
|
|
|
char *result;
|
|
|
|
FILE *fff;
|
|
|
|
|
|
|
|
struct project_info info;
|
2012-05-04 20:55:31 +00:00
|
|
|
struct footer_info footer;
|
|
|
|
struct slide_info slides[MAX_SLIDES];
|
2012-05-03 21:36:02 +00:00
|
|
|
|
|
|
|
if (argc<2) {
|
|
|
|
fprintf(stderr,"\n");
|
|
|
|
fprintf(stderr,"USAGE: %s DIR\n",argv[0]);
|
|
|
|
fprintf(stderr,"\tWhere DIR contains presentation info\n\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read in project info */
|
|
|
|
strncpy(project_directory,argv[1],BUFSIZ);
|
|
|
|
sprintf(filename,"%s/info",project_directory);
|
|
|
|
|
|
|
|
fff=fopen(filename,"r");
|
|
|
|
if (fff==NULL) {
|
|
|
|
fprintf(stderr,"Error! Could not open %s\n",filename);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2012-05-04 20:55:31 +00:00
|
|
|
/* Get Title */
|
|
|
|
while(1) {
|
|
|
|
result=fgets(string,BUFSIZ,fff);
|
|
|
|
if (result==NULL) {
|
|
|
|
fprintf(stderr,"Unexpected EOF finding TITLE in %s\n",filename);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (!strncmp("TITLE",string,5)) break;
|
|
|
|
}
|
2012-05-03 21:36:02 +00:00
|
|
|
result=fgets(string,BUFSIZ,fff);
|
|
|
|
string[strlen(string)-1]='\0';
|
|
|
|
info.title=strdup(string);
|
|
|
|
|
2012-05-04 20:55:31 +00:00
|
|
|
/* Get Author */
|
|
|
|
while(1) {
|
|
|
|
result=fgets(string,BUFSIZ,fff);
|
|
|
|
if (result==NULL) {
|
|
|
|
fprintf(stderr,"Unexpected EOF finding AUTHOR in %s\n",filename);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (!strncmp("AUTHOR",string,6)) break;
|
|
|
|
}
|
2012-05-03 21:36:02 +00:00
|
|
|
result=fgets(string,BUFSIZ,fff);
|
|
|
|
string[strlen(string)-1]='\0';
|
|
|
|
info.author=strdup(string);
|
2012-05-04 20:55:31 +00:00
|
|
|
|
|
|
|
/* Get E-mail */
|
|
|
|
while(1) {
|
|
|
|
result=fgets(string,BUFSIZ,fff);
|
|
|
|
if (result==NULL) {
|
|
|
|
fprintf(stderr,"Unexpected EOF finding EMAIL in %s\n",filename);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (!strncmp("EMAIL",string,5)) break;
|
|
|
|
}
|
2012-05-03 21:36:02 +00:00
|
|
|
result=fgets(string,BUFSIZ,fff);
|
|
|
|
string[strlen(string)-1]='\0';
|
|
|
|
info.email=strdup(string);
|
|
|
|
|
2012-05-04 20:55:31 +00:00
|
|
|
/* Get list of slides */
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
result=fgets(string,BUFSIZ,fff);
|
|
|
|
if (result==NULL) {
|
|
|
|
fprintf(stderr,"Unexpected EOF finding SLIDES in %s\n",filename);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (!strncmp("SLIDES",string,6)) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
info.slides=0;
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
result=fgets(string,BUFSIZ,fff);
|
|
|
|
if (result==NULL) {
|
|
|
|
fprintf(stderr,"Unexpected EOF finding END_SLIDES in %s\n",filename);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (!strncmp("END_SLIDES",string,10)) break;
|
|
|
|
|
|
|
|
string[strlen(string)-1]='\0';
|
|
|
|
slides[info.slides].filename=strdup(string);
|
|
|
|
|
|
|
|
info.slides++;
|
|
|
|
}
|
2012-05-03 21:36:02 +00:00
|
|
|
|
|
|
|
if (result==NULL) fprintf(stderr,"Error reading!\n");
|
|
|
|
|
|
|
|
fclose(fff);
|
|
|
|
|
2012-05-04 20:55:31 +00:00
|
|
|
/************************/
|
|
|
|
/* read in footer info */
|
|
|
|
/************************/
|
|
|
|
|
|
|
|
strncpy(project_directory,argv[1],BUFSIZ);
|
|
|
|
sprintf(filename,"%s/footer",project_directory);
|
|
|
|
|
|
|
|
fff=fopen(filename,"r");
|
|
|
|
if (fff==NULL) {
|
|
|
|
fprintf(stderr,"Error! Could not open %s\n",filename);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
result=fgets(string,BUFSIZ,fff);
|
|
|
|
string[strlen(string)-1]='\0';
|
|
|
|
footer.left=strdup(string);
|
|
|
|
|
|
|
|
result=fgets(string,BUFSIZ,fff);
|
|
|
|
string[strlen(string)-1]='\0';
|
|
|
|
footer.center=strdup(string);
|
|
|
|
|
|
|
|
fclose(fff);
|
|
|
|
|
|
|
|
|
|
|
|
/**************************/
|
|
|
|
/* Generate the program */
|
|
|
|
/**************************/
|
|
|
|
|
2012-05-03 21:36:02 +00:00
|
|
|
/* Print the initial program remarks */
|
|
|
|
generate_initial_comment(info.title,info.author,info.email);
|
|
|
|
|
|
|
|
printf("20 HOME\n");
|
|
|
|
printf("30 P%%=0 : TP%%=%d\n",info.slides-1);
|
|
|
|
|
2012-05-04 20:55:31 +00:00
|
|
|
for(i=0;i<info.slides;i++) {
|
|
|
|
generate_slide(i,info.slides,slides[i].filename);
|
|
|
|
}
|
2012-05-03 21:36:02 +00:00
|
|
|
|
|
|
|
printf("999 END\n");
|
2012-05-02 21:42:03 +00:00
|
|
|
|
2012-05-03 17:40:46 +00:00
|
|
|
generate_keyhandler();
|
2012-05-04 20:55:31 +00:00
|
|
|
generate_footer(footer.left,footer.center,40);
|
2012-05-02 21:42:03 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|