💾 Archived View for mirrors.apple2.org.za › archive › ground.icaen.uiowa.edu › MiscInfo › C › awp.c captured on 2023-06-14 at 18:41:03.
⬅️ Previous capture (2023-01-29)
-=-=-=-=-=-=-
Path: ns-mx!hobbes.physics.uiowa.edu!zaphod.mps.ohio-state.edu!caen!dmag From: dmag@engin.umich.edu (Daniel Demaggio ) Newsgroups: comp.sys.apple2 Subject: AWP file reader in C Summary: Read the subject Keywords: AppleWorks, C Message-ID: <_!2+T3-@engin.umich.edu> Date: 11 May 92 23:49:00 GMT Organization: University of Michigan Engineering, Ann Arbor Lines: 102 Ok, here's a little hack: An AWP file reader in C. It's just something I whipped up in a few hours, so don't expect a filecard interface. Feel free to add/subtract/multiply features yourself. Don`t forget to FTP your AWP files in binary mode. Also, it seems that I'm going to be the new archivist for apple2.archive, so let me know if you have any suggestions. Features: - prints all OA-O options as '--Printer Option' (almost like AppleWorks) - prints all char control codes as '^' (just like AppleWorks) - prints all tab rulers as text (i.e. ===>===) (sort-of like AW) - does not interpret tab rulers, margins, etc.. (nothing like AW) - minimal error checking (like AW, NOT!) - should work will all versions - only reads stdin (i.e. 'a.out < FILE.AWP') - written in just a few hours - throughly tested on 2 AWP files - but hey, what do you want for free? ----- -=- Dan DeMaggio -=- dmag@engin.umich.edu -=- "That is really incredible. That is truly incredible. That is so incredibly incredible that I think I'd like to steal it." -Zaphod ---8<--------------- Cut here ---8<----------------------- #include <stdio.h> /* unix AWP reader by Dan DeMaggio (dmag@caen.engin.umich.edu) */ main(argc,argv,envp) int argc; char *argv[]; char *envp[]; { int c; int mode,byte,vers,skip,cline,byte0; mode = 0; byte = 0; /* byte in file */ vers=0; /* 1 for 3.0 */ skip = 0; /* # bytes to skip in mode 2 */ cline = 0; /* chars on current line */ byte0 = 0; /* first byte of record */ while ((c=getchar()) != EOF ) { switch (mode) { case 0 : /* header */ if (byte == 299) {if (vers==0) mode++; } if (byte == 301) { mode++; } if (byte == 183) if (c!=0) vers++; if (byte == 4) if (c!=79) { printf ("Not AWP file.\n"); exit(1);} break; case 1 : /* looking for start of record */ byte0 = c; mode =2; break; case 2 : /* second byte of line record */ if (c==255) { exit(0); } if (c==208) { /* CR */ printf ("\n"); mode = 1; break; } /* CR */ if (c>208) { printf ("--------Printer Option (%d %d)\n", byte0, c); mode =1; break; } if (c==0) { mode=4; cline=0; break; } printf ("Unknown line record %d %d (at byte %d)\n", byte0, c, byte); break; case 4 : /* text record */ cline++; if (cline==1) { break;} if (cline==2) { if (c>127) c=c-128; byte0=c+2; break;} if (c<25) { if (c<22) printf ("^"); /* control codes */ else printf(" "); /* tab and tab filler */ } else printf ("%c",(char) c); if (cline==byte0) { printf ("\n"); mode=1;} if (cline>150) {printf ("\n\nOOPS! Line too long.\n"); exit(1);} break; } /* end switch */ byte ++; } /* end while */ exit(0); } /* the end */ -- ----- -=- Dan DeMaggio -=- dmag@engin.umich.edu -=- "That is really incredible. That is truly incredible. That is so incredibly incredible that I think I'd like to steal it." -Zaphod