home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / apple2 / 23 < prev    next >
Encoding:
Text File  |  1990-11-26  |  12.0 KB  |  412 lines

  1. Path: wuarchive!zaphod.mps.ohio-state.edu!mips!dimacs.rutgers.edu!aramis.rutgers.edu!paul.rutgers.edu!jac
  2. From: jac@paul.rutgers.edu (Jonathan A. Chandross)
  3. Newsgroups: comp.sources.apple2
  4. Subject: v001SRC003:  AAF Tools (another version)
  5. Message-ID: <Nov.18.20.39.27.1990.22750@paul.rutgers.edu>
  6. Date: 19 Nov 90 01:39:29 GMT
  7. Organization: Rutgers Univ., New Brunswick, N.J.
  8. Lines: 401
  9. Approved: jac@paul.rutgers.edu
  10.  
  11.  
  12. Submitted-by: gwyn@brl.mil
  13. Posting-number: Volume 1, Source:3
  14. Archive-name: archive/aaf_gwyn
  15. Architecture: ANY_2
  16. Version-number: 1.00
  17.  
  18. Enclosed is Doug Gwyn's version of the AAF tools.  These implement
  19. the same functionality as my tools but may be more appropriate to
  20. a different set of C compilers or to your view of how the AAF tools
  21. should work.  
  22.  
  23. You can unpack this with the upaaf.c program I posted earlier.
  24.  
  25. Enjoy.
  26.  
  27. *************************************
  28.  
  29. =Read.Me
  30. -
  31. -Program:    apack
  32. -Function:    pack text files into archive for convenient shipment
  33. -Author:        Douglas A. Gwyn <Gwyn@BRL.MIL>
  34. -Restrictions:    PUBLIC DOMAIN; no restrictions
  35. -
  36. -This program creates an Apple Archive Format (AAF) archive file that
  37. -contains copies of any number of text files; the corresponding "aunpack"
  38. -program may be used to unpack AAF archives back into a set of text files
  39. -with the same contents as the originals.  AAF archives are suitable for
  40. -transmission of collections of text files, including source code, among
  41. -different computer systems, for example via electronic mail and USEnet
  42. -newsgroups.  AAF is the official archive format for the USEnet
  43. -comp.sources.apple2 newsgroup; the article having subject header
  44. -"V001INF001:  Apple Archive Format" in that newsgroup contains the AAF
  45. -specifications.  Note that AAF is not specific to Apple computers, and
  46. -may be used for archiving text files on practically any computer system.
  47. -AAF archives are intentionally not compressed, so that they may be read
  48. -directly, edited, etc. without having to first be unpacked.
  49. -
  50. -See the "apack" source for instructions and further information.
  51. -
  52. =apack.c
  53. -/*
  54. -    apack -- pack text files into archive for convenient shipment
  55. -
  56. -    This source code is the original creation of Douglas A. Gwyn, who
  57. -    has released it into the PUBLIC DOMAIN; there are no restrictions
  58. -    whatever on its further use.  However, it would be unwise to make
  59. -    altered versions that are incompatible with the AAF specification.
  60. -
  61. -    last edit:    31-Oct-1990    D A Gwyn
  62. -
  63. -    INSTRUCTIONS:    Compile this source using almost any hosted
  64. -    implementation of C, and link with the standard C system library,
  65. -    according to whatever procedures are necessary for your particular
  66. -    environment.  To use this program, you must invoke it from an
  67. -    environment that allows you to specify arguments and/or file
  68. -    redirection.
  69. -
  70. -    Usage:    apack files... > archive
  71. -
  72. -    The specified text files are written into the archive, each file
  73. -    preceded by a header line containing "=" followed by the filename.
  74. -    Each line of file data is preceded by "-".  After all files are
  75. -    written, an additional line consisting of "+END" is appended to
  76. -    the archive.  This conforms to the Apple Archive Format (AAF)
  77. -    used for postings to the USEnet comp.sources.apple2 newsgroup.
  78. -
  79. -    Since file contents are copied untranslated into the archive,
  80. -    it is a good idea to not use control characters in the files,
  81. -    as they may be mangled during transmission of the archive.
  82. -    In particular, embedded carriage-returns might be mapped to
  83. -    new-lines on the target system, resulting in incorrect unpacking
  84. -    of the archive.  It is recommended that text lines not exceed 79
  85. -    characters.  For filenames to be maximally portable, they should
  86. -    each consist of an alphabetic character followed by no more than
  87. -    five alphanumeric characters, optionally followed by a "." then
  88. -    one to three additional alphanumeric characters.
  89. -
  90. -    The archive is printable as it stands; the companion program
  91. -    "aunpack" may be used to unpack the archive into files having the
  92. -    same names as the original files.  Because "aunpack" does not
  93. -    check filenames for "funny" characters, but merely attempts to
  94. -    open the named files for writing, if filenames that are not
  95. -    suitable for the target environment were used, those files may
  96. -    not be extracted; in particular, directory path syntax may not
  97. -    be understood.  Fortunately, it is easy to edit an "apack"ed
  98. -    archive to change the filenames when necessary before unpacking.
  99. -
  100. -    If "aunpack" is not available, an "apack"ed archive can fairly
  101. -    easily be manually unpacked with a decent text editor.
  102. -*/
  103. -
  104. -#include    <stdio.h>
  105. -#ifdef __STDC__
  106. -#include    <stdlib.h>
  107. -#include    <string.h>
  108. -#else
  109. -extern void    exit();
  110. -extern char    *strcat(), *strcpy();
  111. -
  112. -#define EXIT_SUCCESS    0
  113. -#define EXIT_FAILURE    1
  114. -#endif
  115. -
  116. -static char    buffer[BUFSIZ];
  117. -
  118. -int
  119. -main( argc, argv )
  120. -    int    argc;
  121. -    char    *argv[];
  122. -    {
  123. -    register int    i;        /* file number */
  124. -    register FILE    *fp = NULL;    /* input text stream */
  125. -
  126. -    for ( i = 1; i < argc; ++i )
  127. -        if ( (fp = fopen( argv[i], "r" )) == NULL )
  128. -            (void)fprintf( stderr, "apack: can't open \"%s\"\n",
  129. -                       argv[i]
  130. -                     );
  131. -        else    {
  132. -            buffer[0] = '=';
  133. -            /*(void)*/strcpy( &buffer[1], argv[i] );
  134. -            /*(void)*/strcat( &buffer[1], "\n" );
  135. -
  136. -            if ( fputs( buffer, stdout ) == EOF )
  137. -                {
  138. -                (void)fprintf( stderr, "apack: write error\n" );
  139. -                exit( EXIT_FAILURE );
  140. -                }
  141. -
  142. -            buffer[0] = '-';
  143. -
  144. -            while ( fgets( &buffer[1], BUFSIZ - 1, fp ) != NULL )
  145. -                if ( fputs( buffer, stdout ) == EOF )
  146. -                    {
  147. -                    (void)fprintf( stderr,
  148. -                               "apack: write error\n"
  149. -                             );
  150. -                    exit( EXIT_FAILURE );
  151. -                    }
  152. -
  153. -            (void)fclose( fp );
  154. -            }
  155. -
  156. -    (void)printf( "+END\n" );
  157. -
  158. -    if ( fflush( stdout ) != 0 )
  159. -        {
  160. -        (void)fprintf( stderr, "apack: write error\n" );
  161. -        exit( EXIT_FAILURE );
  162. -        }
  163. -
  164. -    return EXIT_SUCCESS;
  165. -    }
  166. =aunpack.c
  167. -/*
  168. -    aunpack -- unpack text files from archive for convenient shipment
  169. -
  170. -    This source code is the original creation of Douglas A. Gwyn, who
  171. -    has released it into the PUBLIC DOMAIN; there are no restrictions
  172. -    whatever on its further use.  However, it would be unwise to make
  173. -    altered versions that are incompatible with the PAAF specification.
  174. -
  175. -    last edit:    31-Oct-1990    D A Gwyn
  176. -
  177. -    INSTRUCTIONS:    Save this article, minus the header information,
  178. -    as "aunpack.c".  This particular source is not distributed in
  179. -    PAAF (archived) format, because it is the program that unpacks
  180. -    PAAF files, and if you didn't already have it you would have to
  181. -    manually unpack it, which could be tedious.  Compile this source
  182. -    using almost any hosted implementation of C, and link with the
  183. -    standard C system library, according to whatever procedures are
  184. -    necessary for your particular environment.  It , like the PAAF
  185. -    format, is not Apple-specific, and indeed I use it on several
  186. -    UNIX systems, as well as on my Apple II.  To use this program,
  187. -    you must invoke it from an environment that allows you to specify
  188. -    arguments and/or file redirection.
  189. -
  190. -    Usage:    aunpack [-c] [-r] [-v] < archive
  191. -    or    aunpack [-c] [-r] [-v] archive
  192. -
  193. -    The archive must be in PAAF format, as created by the companion
  194. -    program "apack".  Any line found in the archive that does not
  195. -    start with one of the expected characters ("=", "-", or "+")
  196. -    will be copied to the standard output; anything following a
  197. -    filename header will be sent to that named file.  The -c option
  198. -    permits the continued recognition of tagged lines after a "+"
  199. -    line; the default is for the first "+" to end the archive.  (-c
  200. -    is useful when you have concatenated several PAAF archives into
  201. -    a single file.)  The -r option causes carriage-return characters
  202. -    in the archive to be taken as line terminators; this is not
  203. -    normally necessary, but may be helpful in some special situations.
  204. -    The -v option causes each filename to be printed to the standard
  205. -    error output immediately after successfully opening the file for
  206. -    writing.
  207. -
  208. -    See the "apack" source for further information and the PAAF spec.
  209. -*/
  210. -
  211. -#include    <stdio.h>
  212. -#ifdef __STDC__
  213. -#include    <stdlib.h>
  214. -#include    <string.h>
  215. -#else
  216. -extern void    exit();
  217. -/* #define strchr index    /* if necessary for your system */
  218. -extern char    *strcat(), *strchr(), *strcpy(), *strncpy();
  219. -extern int    strcmp();
  220. -
  221. -#define EXIT_SUCCESS    0
  222. -#define EXIT_FAILURE    1
  223. -#endif
  224. -
  225. -static char    buffer[BUFSIZ];
  226. -static char    iname[BUFSIZ] = { "stdin" };    /* archive input filename */
  227. -static char    oname[BUFSIZ - 1];    /* current output filename */
  228. -static int    status = EXIT_SUCCESS;    /* EXIT_FAILURE if stdout write fails */
  229. -
  230. -int
  231. -main( argc, argv )
  232. -    int    argc;
  233. -    char    *argv[];
  234. -    {
  235. -    register FILE    *ifp = stdin;    /* input stream */
  236. -    register FILE    *ofp = NULL;    /* current output stream */
  237. -    register char    *bp;
  238. -    int        concat = 0;    /* indicates -c flag was specified */
  239. -    int        map_crs = 0;    /* indicates -r flag was specified */
  240. -    int        verbose = 0;    /* indicates -v flag was specified */
  241. -    int        end_seen = 0;    /* indicates "+" record was seen */
  242. -
  243. -    for ( ; argc > 1; ++argv, --argc )
  244. -        if ( strcmp( argv[1], "-v" ) == 0 )
  245. -            verbose = 1;
  246. -        else if ( strcmp( argv[1], "-c" ) == 0 )
  247. -            concat = 1;
  248. -        else if ( strcmp( argv[1], "-r" ) == 0 )
  249. -            map_crs = 1;
  250. -        else            /* not an option */
  251. -            break;
  252. -
  253. -    if ( argc > 1 )
  254. -        if ( (ifp = fopen( argv[1], "r" )) == NULL )
  255. -            {
  256. -            (void)fprintf( stderr, "aunpack: can't open \"%s\"\n",
  257. -                       argv[1]
  258. -                     );
  259. -            exit( EXIT_FAILURE );
  260. -            }
  261. -        else    {
  262. -            iname[0] = '"';
  263. -            /*(void)*/strncpy( &iname[1], argv[1], BUFSIZ - 3 );
  264. -            iname[BUFSIZ - 2] = '\0';    /* just in case */
  265. -            /*(void)*/strcat( &iname[1], "\"" );
  266. -            }
  267. -
  268. -    for ( ; ; )
  269. -        {
  270. -        if ( map_crs )
  271. -            {
  272. -            register int    c;
  273. -
  274. -            bp = buffer;
  275. -
  276. -            do    {
  277. -                if ( (c = getc( ifp )) == EOF )
  278. -                    goto eof_or_error;
  279. -
  280. -                if ( c == '\r' )
  281. -                    c = '\n';
  282. -
  283. -                *bp++ = c;
  284. -                }
  285. -            while ( c != '\n' && bp < &buffer[BUFSIZ - 1] );
  286. -
  287. -            *bp = '\0';
  288. -            }
  289. -        else
  290. -            if ( fgets( buffer, BUFSIZ, ifp ) == NULL )
  291. -                goto eof_or_error;
  292. -
  293. -        if ( (bp = strchr( buffer, '\n' )) == NULL )
  294. -            {
  295. -            (void)fprintf( stderr,
  296. -                  "aunpack: excessively long input line:\n%s\n",
  297. -                       buffer
  298. -                     );
  299. -            goto look_out;
  300. -            }
  301. -
  302. -        switch ( buffer[0] )
  303. -            {
  304. -        case '=':
  305. -            if ( end_seen && !concat )
  306. -                goto junk_line;
  307. -
  308. -            if ( ofp != NULL && fclose( ofp ) != 0 )
  309. -                goto write_error;
  310. -
  311. -            *bp = '\0';    /* remove new-line */
  312. -
  313. -            /*(void)*/strcpy( oname, &buffer[1] );
  314. -
  315. -            if ( (ofp = fopen( oname, "w" )) == NULL )
  316. -                {
  317. -                (void)fprintf( stderr,
  318. -                           "aunpack: can't create \"%s\"\n",
  319. -                           oname
  320. -                         );
  321. -                exit( EXIT_FAILURE );
  322. -                }
  323. -
  324. -            if ( verbose )
  325. -                (void)fprintf( stderr, "%s\n", oname );
  326. -
  327. -            break;
  328. -
  329. -        case '-':
  330. -            if ( end_seen && !concat )
  331. -                goto junk_line;
  332. -
  333. -            if ( ofp == NULL )
  334. -                {
  335. -                (void)fprintf( stderr,
  336. -                          "aunpack: data before filename\n",
  337. -                           oname
  338. -                         );
  339. -                exit( EXIT_FAILURE );
  340. -                }
  341. -
  342. -            if ( fputs( &buffer[1], ofp ) == EOF )
  343. -                goto write_error;
  344. -
  345. -            break;
  346. -
  347. -        case '+':
  348. -            end_seen = 1;
  349. -
  350. -            if ( ofp != NULL && fclose( ofp ) != 0 )
  351. -                goto write_error;
  352. -
  353. -            ofp = NULL;
  354. -
  355. -            break;        /* keep going, in case of more stdout */
  356. -
  357. -        default:
  358. -    junk_line:
  359. -            if ( status == EXIT_SUCCESS
  360. -              && fputs( buffer, stdout ) == EOF
  361. -               )    {
  362. -                (void)fprintf( stderr,
  363. -                           "aunpack: error writing stdout\n"
  364. -                         );
  365. -
  366. -                status = EXIT_FAILURE;    /* keep going, though */
  367. -                }
  368. -
  369. -            break;
  370. -            }
  371. -        }
  372. -
  373. -    write_error:
  374. -
  375. -    (void)fprintf( stderr, "aunpack: error writing \"%s\"\n", oname );
  376. -/*    goto look_out;    */
  377. -
  378. -    look_out:
  379. -
  380. -    if ( ofp != NULL )
  381. -        (void)fprintf( stderr, "aunpack: \"%s\" may be corrupted!\n",
  382. -                   oname
  383. -                 );
  384. -
  385. -    exit( EXIT_FAILURE );
  386. -
  387. -    eof_or_error:
  388. -
  389. -    if ( ferror( ifp ) )
  390. -        {
  391. -        (void)fprintf( stderr, "aunpack: error reading %s\n", iname );
  392. -        goto look_out;
  393. -        }
  394. -
  395. -    if ( !end_seen )
  396. -        {
  397. -        (void)fprintf( stderr, "aunpack: missing \"+\" record\n" );
  398. -        goto look_out;
  399. -        }
  400. -
  401. -    if ( ofp != NULL && fclose( ofp ) != 0 )
  402. -        {
  403. -        (void)fprintf( stderr, "aunpack: error writing \"%s\"\n", oname
  404. -                 );
  405. -        goto look_out;
  406. -        }
  407. -
  408. -    return status;            /* failure is relatively unimportant */
  409. -    }
  410. -
  411. + END OF ARCHIVE
  412.