/********************************************* Program: Morse.exe This program generates a PIC assembler file that contains a morse string. It is intended to generate messages for radio fox hunts. It requires a base file, which MUST be called BASE.PIC *********************************************/ #include #include #include main() { //Variables FILE *rp; FILE *wp; int b, n, y, z; unsigned x; int len=0; char wf[80]; char txt[256]; char *rd; //The Morse Code (1=dot, 3=Dash 4=Space, 5=lsp, 6=Repeat) //Last column is number of elements int morse[64][8] = { 5,0,0,0,0,0,0,1, //Space 3,3,1,1,3,3,0,6, //Exclamation 0,0,0,0,0,0,0,0, //Double Quotes 3,1,3,1,3,0,0,5, //Hash 0,0,0,0,0,0,0,0, //Dollar 0,0,0,0,0,0,0,0, //Percent 0,0,0,0,0,0,0,0, //Ampersand 0,0,0,0,0,0,0,0, //Left Bracket 0,0,0,0,0,0,0,0, //Less Than 0,0,0,0,0,0,0,0, //Right Bracket 0,0,0,0,0,0,0,0, //Star 1,3,1,3,1,0,0,5, //Plus 3,3,1,1,3,3,0,6, //Comma 0,0,0,0,0,0,0,0, //Minus 1,3,1,3,1,3,0,6, //Dot 3,1,1,3,1,0,0,5, //Slash 3,3,3,3,3,0,0,5, //Zero (0) 1,3,3,3,3,0,0,5, //1 1,1,3,3,3,0,0,5, //2 1,1,1,3,3,0,0,5, //3 1,1,1,1,3,0,0,5, //4 1,1,1,1,1,0,0,5, //5 3,1,1,1,1,0,0,5, //6 3,3,1,1,1,0,0,5, //7 3,3,3,1,1,0,0,5, //8 3,3,3,3,1,0,0,5, //9 0,0,0,0,0,0,0,0, //Colon 0,0,0,0,0,0,0,0, //Semi Colon 1,1,1,3,1,3,0,6, //Less Than 3,1,1,1,3,0,0,5, //Equals 1,3,1,1,1,0,0,5, //Greater Than 1,1,3,3,1,1,0,6, //Question Mark 0,0,0,0,0,0,0,0, //At 1,3,0,0,0,0,0,2, //Letter A 3,1,1,1,0,0,0,4, //B 3,1,3,1,0,0,0,4, //C 3,1,1,0,0,0,0,3, //D 1,0,0,0,0,0,0,1, //E 1,1,3,1,0,0,0,4, //F 3,3,1,0,0,0,0,3, //G 1,1,1,1,0,0,0,4, //H 1,1,0,0,0,0,0,2, //I 1,3,3,3,0,0,0,4, //J 3,1,3,0,0,0,0,3, //K 1,3,1,1,0,0,0,4, //L 3,3,0,0,0,0,0,2, //M 3,1,0,0,0,0,0,2, //N 3,3,3,0,0,0,0,3, //O 1,3,3,1,0,0,0,4, //P 3,3,1,3,0,0,0,4, //Q 1,3,1,0,0,0,0,3, //R 1,1,1,0,0,0,0,3, //S 3,0,0,0,0,0,0,1, //T 1,1,3,0,0,0,0,3, //U 1,1,1,3,0,0,0,4, //V 1,3,3,0,0,0,0,3, //W 3,1,1,3,0,0,0,4, //X 3,1,3,3,0,0,0,4, //Y 3,3,1,1,0,0,0,4, //Z 0,0,0,0,0,0,0,0, //Left Hand Bracket 0,0,0,0,0,0,0,0, //Backslash 0,0,0,0,0,0,0,0, //Right Hand Bracket 6,0,0,0,0,0,0,1, //Power of 0,0,0,0,0,0,0,0}; //Underline //Open BASE.PIC file rp = fopen("base.pic", "r"); if (rp == 0) { printf("\nCannot open BASE.PIC file"); return; } printf("Enter name of file to create: "); gets(wf); wp = fopen(wf, "r"); if (wp) { fclose(wp); printf("\nFile already exists!!!"); return; } wp = fopen(wf, "w"); if (wp == 0) { printf("\nCannot open write file"); return; } //Files are open - Now copy contents! fgets(txt, 255, rp); do { if (!fputs(txt, wp)) { printf("\nError copying BASE.PIC file"); fclose(rp); fclose(wp); return; } rd = fgets(txt, 255, rp); }while (rd); //Files are copied - close read file fclose(rp); printf("\nFor morse Break use Equals(=), End of Message(AR) use Plus(+)," "\nfor End of Work(VA) use Less Than(<), Wait(AS) use Greater Than(>)," "\nfor Preliminary call(CT) use Hash(#).\n\n"); printf("To have the message repeat continuously, use circumflex (^)\n\n"); //Get string to morsify do{ printf("\nEnter string to include: "); gets(txt); printf("\nText will be converted as:\n"); for (x=0; x 127) b = 0; else if (z < 32) b = 0; else if(z > 95) z = z - 32; z -= 32; if (z < 64) b = morse[z][7]; if(b != 0) printf("%c", txt[x]); } printf("\n\nThe following characters will not be converted:\n"); y=0; for (x=0; x 127) b = 0; else if (z < 32) b = 0; else if (z > 95) z = z - 32; z -= 32; if (z < 64) b = morse[z][7]; if(b == 0) { printf("%c", txt[x]); y=1; } } if (y==0) printf("None"); printf("\n\nDo you want to convert this string." "\nEnter Y to convert or N to enter another string "); gets(wf); }while ((((int) wf[0]) | 0x20 )!= 0x79); //Now do the conversion! for (x=0; x 127) b = 0; else if (z < 32) b = 0; else if (z > 95) z = z - 32; z -= 32; if (z < 64) { y = morse[z][7]; for (n=0; n