/* * **** DO CMD **** * * This file contains functions to process commands * */ #include #include #include #include "pscover.h" not(FILE *fp, FILE *ofp, char *buf, struct keytab *cmd) { if (debugsw) print_parms("not", fp, ofp, buf, cmd); /* debug */ fprintf(ofp,"command %s not implemented (%s)\n", cmd->key_word, buf); } void do_err(FILE *fp, FILE *ofp, char *buf, struct keytab *cmd) { if (debugsw) print_parms("do_err", fp, ofp, buf, cmd); /* debug */ fprintf(stderr,"Error: %s (%s)\n", cmd->key_word, buf); } void do_set(FILE *fp, FILE *ofp, char *buf, struct keytab *cmd) { char *var; /* variable name */ char *p; /* parsing pointer */ if (debugsw) print_parms("do_set", fp, ofp, buf, cmd); /* debug */ p = cmd_dat; /* command data */ if (*p == '\0') { /* nothing to set */ fprintf(stderr,"%s: Nothing following set command (%s)\n", Prog, buf); return; } while (isspace(*p)) p++; var = p; /* beginning of variable name */ while (*p != '\0' && ! isspace(*p)) p++; /* find end of name */ if (*p == '\0') { /* no value */ fprintf(stderr,"%s: No value given for set command (%s)\n", Prog, buf); return; } *p++ = '\0'; /* terminate variable name */ while (*p != '\0' && isspace(*p)) p++; /* find start of value */ fprintf(ofp,"/%s %s def\n", var, p); } void do_newfont(FILE *fp, FILE *ofp, char *buf, struct keytab *cmd) { char *font; /* font name */ char *p; /* parse pointer */ if (debugsw) print_parms("do_newfont", fp, ofp, buf, cmd); /* debug */ /* find end of newfont command */ p = cmd_dat; /* data following command */ if (*p == '\0') { fprintf(stderr,"%s: No font name given for newfont command (%s)\n", Prog, buf); return; } /* now find beginning of font name */ while (*p != '\0' && isspace(*p)) p++; font = p; /* font name */ while (*p != '\0' && ! isspace(*p)) p++; /* find end of name */ if (p == '\0') { fprintf(stderr,"%s: No font size given for newfont command (%s)\n", Prog, buf); return; } *p++ = '\0'; /* terminate font name */ while (*p != '\0' && isspace(*p)) p++; /* find beginning of size */ fprintf(ofp,"%s %s NewFont\n", font, p); } void do_songs(FILE *fp, FILE *ofp, char *buf, struct keytab *cmd) { /* set default justification of songs */ if (debugsw) print_parms("do_songs", fp, ofp, buf, cmd); /* debug */ if (cmd_just == CMD_FULL) cmd_just = CMD_CENT; song_just = cmd_just; /* record justification for songs */ fprintf(ofp,"%% Song justification: "); out_just(cmd_just,ofp); fprintf(ofp,"\n"); } void do_newline(FILE *fp, FILE *ofp, char *buf, struct keytab *cmd) { if (debugsw) print_parms("do_newline", fp, ofp, buf, cmd); /* debug */ if (strcmp(cmd->key_word,"newline")) fprintf(ofp,"OldLine\n"); else fprintf(ofp,"NewLine\n"); /* output newline */ } void do_noise(FILE *fp, FILE *ofp, char *buf, struct keytab *cmd) { if (debugsw) print_parms("do_noise", fp, ofp, buf, cmd); /* debug */ /* output string for noise suppression */ dat_str(ofp); /* output the string itself */ fprintf(ofp,"PrintNoise\n"); } void do_date(FILE *fp, FILE *ofp, char *buf, struct keytab *cmd) { if (debugsw) print_parms("do_date", fp, ofp, buf, cmd); /* debug */ dat_str(ofp); fprintf(ofp,"PrintDate\n"); } void do_side(FILE *fp, FILE *ofp, char *buf, struct keytab *cmd) { if (debugsw) print_parms("do_side", fp, ofp, buf, cmd); /* debug */ if (cmd_just == CMD_CENT) cmd_just = CMD_FULL; out_just(cmd_just, ofp); fprintf(ofp,"Side\n"); song_just = CMD_LEFT; /* assume left justification */ } void do_tab(FILE *fp, FILE *ofp, char *buf, struct keytab *cmd) { if (debugsw) print_parms("do_tab", fp, ofp, buf, cmd); /* debug */ dat_str(ofp); if (cmd_just == CMD_CENT) cmd_just = CMD_FULL; out_just(cmd_just, ofp); fprintf(ofp,"Tab\n"); } void do_title(FILE *fp, FILE *ofp, char *buf, struct keytab *cmd) { if (debugsw) print_parms("do_title", fp, ofp, buf, cmd); /* debug */ dat_str(ofp); if (cmd_just == CMD_CENT) cmd_just = CMD_FULL; out_just(cmd_just, ofp); fprintf(ofp,"Title\n"); } void do_artist(FILE *fp, FILE *ofp, char *buf, struct keytab *cmd) { if (debugsw) print_parms("do_artist", fp, ofp, buf, cmd); /* debug */ dat_str(ofp); if (cmd_just == CMD_CENT) cmd_just = CMD_FULL; out_just(cmd_just, ofp); fprintf(ofp,"Artist\n"); } void do_wrapup(FILE *fp, FILE *ofp, char *buf, struct keytab *cmd) { if (debugsw) print_parms("do_wrapup", fp, ofp, buf, cmd); /* debug */ fprintf(ofp,"WrapUp\n"); } void do_cover(FILE *fp, FILE *ofp, char *buf, struct keytab *cmd) { if (debugsw) print_parms("do_cover", fp, ofp, buf, cmd); /* debug */ if (cmd_just != CMD_LEFT && cmd_just != CMD_CENT && cmd_just != CMD_RIGHT) { /* illegal cover side */ fprintf(stderr,"%s: Invalid cover type (%s)\n", Prog, buf); return; } if (cmd_just == CMD_LEFT) new_page(ofp); out_just(cmd_just, ofp); fprintf(ofp,"Cover\n"); } void do_song(FILE *fp, FILE *ofp, char *buf, struct keytab *cmd) { /* print song or line */ if (debugsw) print_parms("do_song", fp, ofp, buf, cmd); /* debug */ if (cmd_just == CMD_FULL) cmd_just = CMD_CENT; dat_str(ofp); /* output data */ out_just(cmd_just, ofp); /* output justification */ if (strcmp(cmd->key_word,"print")) fprintf(ofp,"Line\n"); else fprintf(ofp,"Song\n"); } void do_dblsong(FILE *fp, FILE *ofp, char *buf, struct keytab *cmd) { char *p, *q; /* parsing pointers */ if (debugsw) print_parms("do_dblsong", fp, ofp, buf, cmd); /* debug */ if ((p = cmd_dat) == '\0') { fprintf(stderr,"No song titles given for double song (%s)\n", buf); return; } while (*p != '\0' && isspace(*p)) p++; /* find non-blank */ for (q = p; *q != '\0' && *q != '\t'; q++); /* find second string */ if (*q != '\0') { /* end of first string - find start of second string */ *q++ = '\0'; /* terminate first string */ while (*q != '\0' && isspace(*q)) q++; /* start of second string */ } if (*q == '\0') { fprintf(stderr,"No second string given for double song (%s)\n", buf); return; } out_str(p, ofp); /* output left string */ out_str(q, ofp); /* output right string */ if (strcmp(cmd->key_word,"doublesong")) fprintf(ofp,"DoubleLine\n"); else fprintf(ofp,"DoubleSong\n"); } void do_marg(FILE *fp, FILE *ofp, char *buf, struct keytab *cmd) { if (debugsw) print_parms("do_marg", fp, ofp, buf, cmd); /* debug */ fprintf(ofp,"Go"); if (cmd_just == CMD_FULL) cmd_just = CMD_CENT; out_just(cmd_just, ofp); fprintf(ofp,"\n"); } void do_code(FILE *fp, FILE *ofp, char *buf, struct keytab *cmd) { if (debugsw) print_parms("do_code", fp, ofp, buf, cmd); /* debug */ if (strcmp(cmd->key_word,"endcode") == 0) { fprintf(stderr,"EndCode without a BegCode!\n"); return; } fprintf(ofp,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"); fprintf(ofp,"%%%% BEGIN USER CODE\n"); fprintf(ofp,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"); while (get_line(buf,BUFSIZ,fp) != NULL) { /* loop reading the input file */ cmd = find_cmd(buf); if (strcmp(cmd->key_word,"endcode") == 0) break; fputs(buf,ofp); /* output code as is */ } fprintf(ofp,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"); fprintf(ofp,"%%%% END USER CODE\n"); fprintf(ofp,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"); } void out_just(int just, FILE *ofp) { /* output a justification string */ switch(just) { case CMD_LEFT: fprintf(ofp,"Left"); break; case CMD_FULL: fprintf(ofp,"Full"); break; case CMD_RIGHT: fprintf(ofp,"Right"); break; case CMD_CENT: fprintf(ofp,"Center"); break; default: fprintf(stderr,"%s: Internal error - invalid justification (%d)n", Prog, just); } } void dat_str(FILE *ofp) { /* output data as a string */ while (isspace(*cmd_dat)) cmd_dat++; /* find non-blank */ out_str(cmd_dat, ofp); } void out_str(char *p, FILE *ofp) { /* output string */ int c; /* int storage for char */ fprintf(ofp,"("); if (*p != '\0') { /* data found - output it */ for (; *p != '\0'; p++) switch (c = *p) { /* output character */ case '(': fprintf(ofp,"\\("); break; case ')': fprintf(ofp,"\\)"); break; case '{': fprintf(ofp,"\\{"); break; case '}': fprintf(ofp,"\\}"); break; default: fputc(c,ofp); break; } } fprintf(ofp,")"); } void print_song(char *buf, FILE *ofp) { /* print a song */ cmd_dat = buf + 1; /* skip initial tab */ dat_str(ofp); /* output song title */ out_just(song_just,ofp); /* song justification */ fprintf(ofp,"Song\n"); } void print_parms(char *fname, FILE * fp, FILE *ofp, char *buf, struct keytab *cmd) { /* actuall, this never gets called, but it keeps lint & debugger happy */ fprintf(stderr,"Function %s, fp=%x, ofp=%x\n", fname, fp, ofp); fprintf(stderr,"buf >>%s<<\n", buf); fprintf(stderr,"keytab >>%s<<, %d, %d\n", cmd->key_word, cmd->key_type, cmd->key_mask); }