File: build-prc.c

package info (click to toggle)
prc-tools 0.5.0r-3.1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 20,412 kB
  • ctags: 16,426
  • sloc: ansic: 35,388; makefile: 443; asm: 213; cpp: 194; perl: 59
file content (97 lines) | stat: -rw-r--r-- 1,969 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* ptst.c:  build a .prc from a pile of files.
 *
 * (c) 1996, Dionne & Associates
 * (c) 1997, The Silver Hammer Group Ltd.
 * This is Free Software, under the GNU Public Licence v2 or greater.
 */

#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include "prc.h"

#ifdef __CYGWIN32__
#define O_PLATFORM O_BINARY
#else
#define O_PLATFORM 0
#endif

main(int argc, char *argv[])
{
  pfd_t *pf;
  int fd;
  int i;
  char *sd;
  char sname[5];
  int slen;
  int opt;
  char *type = "appl";
  int optind = 1;

  if (argc < 5) {
    fprintf(stderr, "Usage: %s [-Ll] [-t type] fname.prc 'App Name' apid resource resource ...\n", argv[0]);
    exit (1);
  }

  while (optind < argc && argv[optind][0] == '-') {
    opt = argv[optind++][1];

    switch (opt) {

    case 'l':
      type = "GLib";
      break;
    case 'L':
      type = "libr";
      break;
    case 't':
      type = argv[optind++];
      break;
    case '?':
    default :
      fprintf(stderr, "%s Unknown option\n", argv[0]);
      exit (2);
      break;
    }
  }

  if (!(pf = openw_pfd(argv[optind + 1], argv[optind + 2], argv[optind], type))) {
    printf ("can't open prc file\n");
    exit(2);
  }

  /* the .prc write routines write the resources in reverse order! */

  for (i=argc-1; i > optind + 2; i--) {
    char *rname;

    if ((fd = open(argv[i], O_PLATFORM | O_RDONLY)) < 1) {
      fprintf(stderr, "Can't open resource file %s\n",argv[i]);
      exit(3);
    }

    rname = strchr(argv[i], '/');
    if (!rname) rname = argv[i];
    else rname++;		/* skip over the / */
    if (strlen(rname) <= 4) {
      fprintf(stderr, "%s not in proper [name][id] form\n", argv[i]);
      exit(4);
    }

    slen = lseek(fd, 0, SEEK_END);
    lseek(fd, 0, SEEK_SET);

    sd = malloc(slen);
    read(fd, sd, slen);
    close (fd);

    add_section_pfd(pf, rname, strtoul(rname + 4, (void *)0, 16),
		    sd, slen);
  }

  write_pfd(pf);
  exit(0);
}