home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / apple2 / 22 < prev    next >
Encoding:
Text File  |  1990-11-26  |  13.0 KB  |  550 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: v001SRC002:  Apple Archive Format tools
  5. Message-ID: <Nov.18.20.34.21.1990.21934@paul.rutgers.edu>
  6. Date: 19 Nov 90 01:34:22 GMT
  7. Organization: Rutgers Univ., New Brunswick, N.J.
  8. Lines: 539
  9. Approved: jac@paul.rutgers.edu
  10.  
  11.  
  12. Submitted-by: jac@paul.rutgers.edu
  13. Posting-number: Volume 1, Source:2
  14. Archive-name: archive/aaf_jac
  15. Architecture: ANY_2
  16. Version-number: 1.00
  17.  
  18. Enclosed is my version of the AAF tools.  These include the pack and
  19. unpack programs as well as documentation and a Makefile.
  20.  
  21. The upaaf program I posted earlier should be used to unpack this archive.
  22.  
  23. ******************************
  24.  
  25. =Read.Me
  26. -
  27. -Apple Archive Format
  28. -Version 1.00
  29. -
  30. -COPYRIGHT 1990 by Jonathan A. Chandross.
  31. -All Rights Reserved.
  32. -
  33. -The AAF is a simple archive format designed for shipping around Apple
  34. -source code.  An archive consists of a series of lines.  Each line is
  35. -interpreted according to the first character of the line.  The
  36. -interpretations are:
  37. -
  38. -    =       the name of the unpacked file starting here
  39. -    -       a source line to be unpacked into the current file
  40. -    +       end of archive.
  41. -
  42. -Lines beginning with any other character are simply output to the console.
  43. -
  44. -A simple example of this format:
  45. -    From: random@foobar.com
  46. -    To: freeworld
  47. -    Subject: First program.
  48. -            R.
  49. -    =helloworld.c
  50. -    -main()
  51. -    -{
  52. -    -       printf("Hello World\n");
  53. -    -}
  54. -    =Read.Me
  55. -    -Test out a C compiler; just compile and execute.
  56. -    + All done.
  57. -    J. Random Hacker
  58. -    random@foobar.com
  59. -
  60. -This file would create the files "helloworld.c" and "Read.Me".  When
  61. -the archive was unpacked, all of the non-source and non-file-name
  62. -lines would be output to the console until the '+' was encountered.
  63. -
  64. -Using '=' to specify a file name and '-' to specify a line of source
  65. -allows a standard USENET or email file to be unpacked without removing
  66. -any preamble or trailing information.
  67. -
  68. -The '+' at the end of the file indicates the end of an archive.  Lines
  69. -occurring past this point will not be processed at all.
  70. -
  71. -The '=' and "+" sentinels are due to Doug Gwyn.
  72. -
  73. -
  74. -Jonathan A. Chandross
  75. -jac@paul.rutgers.edu
  76. -November 1990
  77. -
  78. =Makefile
  79. -
  80. -FLAGS =        -g
  81. -DEFINES =    -D SHELL
  82. -
  83. -all: paaf.c upaaf.c
  84. -
  85. -paaf: paaf.c
  86. -    cc ${DEFINES} ${FLAGS} -o paaf paaf.c
  87. -
  88. -upaaf: upaaf.c
  89. -    cc ${DEFINES} ${FLAGS} -o upaaf upaaf.c
  90. -
  91. -lint:
  92. -    lint paaf.c
  93. -    lint upaaf.c
  94. -
  95. -clean:
  96. -    rm -f paaf upaaf
  97. -
  98. =paaf.c
  99. -
  100. -/*
  101. - *******************************************************************************
  102. - *
  103. - * paaf.c
  104. - *
  105. - * Pack an archive in Apple Archive Format.
  106. - *
  107. - * Another quality product handcrafted with loving care by:
  108. - *    Jonathan A. Chandross
  109. - *    jac@paul.rutgers.edu
  110. - *    November 1990
  111. - *
  112. - * COPYRIGHT 1990 by Jonathan A. Chandross
  113. - * All rights reserved.
  114. - *
  115. - * Use "cc -D SHELL" to compile for use with a shell.
  116. - *
  117. - *******************************************************************************
  118. - */
  119. -
  120. -#include <stdio.h>
  121. -
  122. -/*
  123. - *******************************************************************************
  124. - *
  125. - * Defines
  126. - *
  127. - * EXPORT        function is visible outside this module
  128. - * IMPORT        function is defined outside this module
  129. - * STATIC        function is invisible outside this module
  130. - *
  131. - * LENGTH        length of strings
  132. - *
  133. - *******************************************************************************
  134. - */
  135. -#define EXPORT
  136. -#define IMPORT    extern
  137. -#define LOCAL    static
  138. -
  139. -#define LENGTH    255
  140. -
  141. -/*
  142. - *******************************************************************************
  143. - *
  144. - * main
  145. - *
  146. - * Packs a series of files in Apple Archive Format
  147. - * 
  148. - * Parameters:
  149. - *    argc            number of command line arguments if compiled
  150. - *                for a shell
  151. - *    argv            command line argument vector
  152. - * Locals:
  153. - *    archive_name        name of archive to pack if not using a shell
  154. - * Returns:
  155. - *
  156. - * If this program is compiled for use with a shell, the first command line
  157. - * argument is considered to contain a list of file names to archive.  If
  158. - * this program is compiled stand-alone, i.e. not for use with a shell, it
  159. - * prompts for the files to pack.
  160. - *
  161. - * The SHELL define is an unsightly way to do things, but there is little
  162. - * choice if this program is to be used on an Apple lacking some sort of
  163. - * shell.
  164. - *
  165. - *******************************************************************************
  166. - */
  167. -#ifdef SHELL
  168. -EXPORT int main(argc, argv)
  169. -int        argc;
  170. -char        *argv[];
  171. -#else
  172. -EXPORT int main()
  173. -#endif
  174. -{
  175. -IMPORT    void    pack();
  176. -IMPORT    int    fclose();
  177. -#ifdef SHELL
  178. -IMPORT    void    usage();
  179. -#else
  180. -char        archive_file_name[LENGTH];
  181. -FILE        *archive_file;
  182. -#endif
  183. -
  184. -#ifdef SHELL
  185. -    /*
  186. -     * If we are using a shell, then argv[] will contain the names of the
  187. -     * files to pack into an archive.
  188. -     */
  189. -    if(argc == 1) {
  190. -        usage(argv[0]);
  191. -        exit(1);
  192. -        }
  193. -    else {
  194. -        /*
  195. -         * argc is always 1 more than the number of arguments since
  196. -         * argv[0] contains the name of the program.  This means we
  197. -         * have to correct for the array basing whenever we use an
  198. -         * argument.
  199. -         */
  200. -        int        arg_num;
  201. -
  202. -        for(arg_num = 2; arg_num <= argc; arg_num++) {
  203. -            (void) fprintf(stderr,
  204. -                    "Packing file: '%s'\n",
  205. -                    argv[arg_num - 1]);
  206. -            pack(argv[arg_num - 1], stdout);
  207. -            }
  208. -        (void) fputs("+ END OF ARCHIVE\n\n", stdout);
  209. -        }
  210. -#else
  211. -    (void) fputs("Archive name:", stdout);
  212. -    if(scanf("%s", archive_file_name) == EOF)
  213. -        exit(1);
  214. -
  215. -    if((archive_file = fopen(archive_file_name, "w")) == (FILE *)EOF) {
  216. -        (void) fprintf(stderr,
  217. -            "Error: could not open archive file '%s'\n",
  218. -            archive_file_name);
  219. -        exit(1);
  220. -        }
  221. -
  222. -    for(;;) {
  223. -        char        buffer[LENGTH];
  224. -
  225. -        (void) fputs("File name to archive:", stdout);
  226. -        if(scanf("%s", buffer) == EOF)
  227. -            break;
  228. -        else
  229. -            pack(buffer, archive_file);
  230. -        }
  231. -    (void) fputs("+ END OF ARCHIVE\n\n", archive_file);
  232. -    (void) fclose(archive_file);
  233. -#endif
  234. -
  235. -    return(0);
  236. -}
  237. -
  238. -/*
  239. - *******************************************************************************
  240. - *
  241. - * usage
  242. - *
  243. - * Print out a message on how to use this program
  244. - * 
  245. - * Parameters:
  246. - *    object_name        name of object file storing this program
  247. - * Locals:
  248. - * Returns:
  249. - *
  250. - *******************************************************************************
  251. - */
  252. -#ifdef SHELL
  253. -LOCAL void usage(object_name)
  254. -char        *object_name;
  255. -{
  256. -    (void) fprintf(stderr,
  257. -            "Usage: %s file_1 [file_2] [file_3] [...]\n",
  258. -            object_name);
  259. -}
  260. -#endif
  261. -
  262. -/*
  263. - *******************************************************************************
  264. - *
  265. - * pack
  266. - *
  267. - * pack an archive
  268. - * 
  269. - * Parameters:
  270. - *    file_name        name of file to add to archive
  271. - *    output_file        archive file (appended to)
  272. - * Locals:
  273. - *    buffer            holds each line as it is read out of archive
  274. - *    file            file to archive
  275. - * Returns:
  276. - *
  277. - *******************************************************************************
  278. - */
  279. -LOCAL void pack(file_name, output_file)
  280. -char        *file_name;
  281. -FILE        *output_file;
  282. -{
  283. -IMPORT    char    *fgets();
  284. -IMPORT    int    fputs();
  285. -IMPORT    int    fclose();
  286. -IMPORT    FILE    *fopen();
  287. -char        buffer[LENGTH];
  288. -FILE        *file;
  289. -
  290. -    /*
  291. -     * Open the file to archive and make sure it exists.
  292. -     */
  293. -    if((file = fopen(file_name, "r")) == (FILE *)NULL) {
  294. -        (void) fprintf(stderr,
  295. -                   "Error: could not open file '%s'\n",
  296. -                   file_name);
  297. -        exit(1);
  298. -        }
  299. -
  300. -    /*
  301. -     * Put the file name in the output
  302. -     */
  303. -    (void) fprintf(output_file, "=%s\n", file_name);
  304. -    
  305. -    /*
  306. -     * As long as the file is not empty, process lines.  Each line
  307. -     * to be output has a leading '-'.
  308. -     */
  309. -    buffer[0] = '-';
  310. -    while(fgets(&buffer[1], LENGTH, file) != (char *)NULL) {
  311. -        /*
  312. -         * Add the line to the output file with a leading '-'.
  313. -         */
  314. -        (void) fputs(buffer, output_file);
  315. -        }
  316. -
  317. -    /*
  318. -     * Done with this file.
  319. -     */
  320. -    (void) fclose(file);
  321. -}
  322. -
  323. =upaaf.c
  324. -
  325. -/*
  326. - *******************************************************************************
  327. - *
  328. - * upaaf.c
  329. - *
  330. - * Unpack an archive in apple format.
  331. - *
  332. - * Another quality product handcrafted with loving care by:
  333. - *    Jonathan A. Chandross
  334. - *    jac@paul.rutgers.edu
  335. - *    November 1990
  336. - *
  337. - * COPYRIGHT 1990 by Jonathan A. Chandross
  338. - * All rights reserved.
  339. - *
  340. - * Use "cc -D SHELL" to compile for use with a shell.
  341. - *
  342. - *******************************************************************************
  343. - */
  344. -
  345. -#include <stdio.h>
  346. -
  347. -/*
  348. - *******************************************************************************
  349. - *
  350. - * Defines
  351. - *
  352. - * EXPORT        function is visible outside this module
  353. - * IMPORT        function is defined outside this module
  354. - * STATIC        function is invisible outside this module
  355. - *
  356. - * LENGTH        length of strings
  357. - *
  358. - *******************************************************************************
  359. - */
  360. -#define EXPORT
  361. -#define IMPORT    extern
  362. -#define LOCAL    static
  363. -
  364. -#define LENGTH    255
  365. -
  366. -/*
  367. - *******************************************************************************
  368. - *
  369. - * main
  370. - *
  371. - * Unpacks a file in Apple Archive Format
  372. - * 
  373. - * Parameters:
  374. - *    argc            number of command line arguments if compiled
  375. - *                for a shell
  376. - *    argv            command line argument vector
  377. - * Locals:
  378. - *    archive_name        name of archive to unpack if not using a
  379. - *                shell
  380. - * Returns:
  381. - *
  382. - * If this program is compiled for use with a shell, the first command line
  383. - * argument is considered to contain the name of the archive to unpack.  If
  384. - * this program is compiled stand-alone, i.e. not for use with a shell, it
  385. - * prompts for the archive to unpack.
  386. - *
  387. - * The SHELL define is an unsightly way to do things, but there is little
  388. - * choice if this program is to be used on an Apple lacking some sort of
  389. - * shell.
  390. - *
  391. - *******************************************************************************
  392. - */
  393. -#ifdef SHELL
  394. -EXPORT int main(argc, argv)
  395. -int        argc;
  396. -char        *argv[];
  397. -#else
  398. -EXPORT int main()
  399. -#endif
  400. -{
  401. -IMPORT    void    unpack();
  402. -#ifdef SHELL
  403. -IMPORT    void    usage();
  404. -#else
  405. -char        archive_name[LENGTH];
  406. -#endif
  407. -
  408. -#ifdef SHELL
  409. -    /*
  410. -     * If we are using a shell, then argv[1] will be the name of the
  411. -     * archive to unpack.
  412. -     */
  413. -    if(argc == 2)
  414. -        unpack(argv[1]);
  415. -    else {
  416. -        usage(argv[0]);
  417. -        exit(1);
  418. -        }
  419. -#else
  420. -    (void) fputs("Enter name of archive to unpack:", stdout);
  421. -    (void) scanf("%s", archive_name);
  422. -    unpack(archive_name);
  423. -#endif
  424. -
  425. -    return(0);
  426. -}
  427. -
  428. -/*
  429. - *******************************************************************************
  430. - *
  431. - * usage
  432. - *
  433. - * Print out a message on how to use this program
  434. - * 
  435. - * Parameters:
  436. - *    object_name        name of object file storing this program
  437. - * Locals:
  438. - * Returns:
  439. - *
  440. - *******************************************************************************
  441. - */
  442. -#ifdef SHELL
  443. -LOCAL void usage(object_name)
  444. -char        *object_name;
  445. -{
  446. -    (void) fprintf(stderr, "Usage: %s archive-name\n", object_name);
  447. -}
  448. -#endif
  449. -
  450. -/*
  451. - *******************************************************************************
  452. - *
  453. - * unpack
  454. - *
  455. - * Unpack an archive
  456. - * 
  457. - * Parameters:
  458. - *    archive_file_name    name of archive file to unpack
  459. - * Locals:
  460. - *    buffer            holds each line as it is read out of archive
  461. - *    archive_file        archive file
  462. - *    output_file        current file being unpacked from archive
  463. - * Returns:
  464. - *
  465. - *******************************************************************************
  466. - */
  467. -LOCAL void unpack(archive_file_name)
  468. -char        *archive_file_name;
  469. -{
  470. -IMPORT    char    *fgets();
  471. -IMPORT    int    fput();
  472. -IMPORT    int    strlen();
  473. -IMPORT    int    fclose();
  474. -IMPORT    FILE    *fopen();
  475. -char        buffer[LENGTH];
  476. -FILE        *archive_file;
  477. -FILE        *output_file = (FILE *)NULL;
  478. -
  479. -    /*
  480. -     * Open the archive file and make sure it exists.
  481. -     */
  482. -    if((archive_file = fopen(archive_file_name, "r")) == (FILE *)NULL) {
  483. -        (void) fprintf(stderr, "Error: could not open archive '%s'\n",
  484. -            archive_file_name);
  485. -        exit(1);
  486. -        }
  487. -    
  488. -    /*
  489. -     * As long as the file is not empty, process lines
  490. -     */
  491. -    while(fgets(buffer, LENGTH, archive_file) != (char *)NULL) {
  492. -        /*
  493. -         * What kind of line do we have? 
  494. -         */
  495. -        switch(buffer[0]) {
  496. -             case '=':
  497. -            /*
  498. -             * Have a file name.  Remove the trailing newline
  499. -             * from the file-name (left by fgets) by overwriting
  500. -             * with a Null.  Then open the file and verify that
  501. -             * we can write to it.  Skip over the first character
  502. -             * in the file-name (it is an '=') 
  503. -             */
  504. -            buffer[strlen(buffer) - 1] = '\0';
  505. -            (void) fprintf(stdout, "Unpacking '%s'\n", &buffer[1]);
  506. -
  507. -            /*
  508. -             * If we have an open output file, close it.
  509. -             */
  510. -            if(output_file != (FILE *)NULL)
  511. -                (void) fclose(output_file);
  512. -
  513. -            if((output_file = fopen(&buffer[1], "w")) ==
  514. -               (FILE *)EOF) {
  515. -                (void) fprintf(stderr,
  516. -                    "Error: could not open '%s'\n", buffer);
  517. -                exit(1);
  518. -                }
  519. -            break;
  520. -             case '-':
  521. -            /*
  522. -             * Have a line of source.  Add the line to the output
  523. -             * file without the leading "-".
  524. -             */
  525. -            if(output_file == (FILE *)NULL) {
  526. -                fputs("Error: no file specified.\n", stderr);
  527. -                exit(1);
  528. -                }
  529. -            else
  530. -                (void) fputs(&buffer[1], output_file);
  531. -            break;
  532. -             case '+':
  533. -            /*
  534. -             * End of archive.  Exit.
  535. -             */
  536. -            exit(0);
  537. -            break;
  538. -             default:
  539. -            /*
  540. -             * Have some other type of line (mail header,
  541. -             * signature, comment, etc.)  Output it.
  542. -             */
  543. -            (void) fputs(&buffer[0], stdout);
  544. -            break;
  545. -             }
  546. -        }
  547. -}
  548. -
  549. + END OF ARCHIVE
  550.