source: buchla-68k/orig/GEMDOS/SIZES.C@ 4b63bf3

Last change on this file since 4b63bf3 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Imported original source code.

  • Property mode set to 100755
File size: 3.2 KB
Line 
1/*
2 ============================================================================
3 sizes.c -- stat an absolute format Alcyon object file
4 Version 9 -- 1989-02-01 -- D.N. Lynx Crowe
5 ============================================================================
6*/
7
8#include "stdio.h"
9#include "stddefs.h"
10#include "portab.h"
11#include "objdefs.h"
12#include "biosdefs.h"
13
14extern FILE *fopenb();
15extern int fclose(), fread(), flread();
16extern long getl();
17
18FILE *B_file; /* file pointer */
19
20struct EXFILE B_fhdr; /* executable file header */
21
22long B_txt_o, /* text origin from file header */
23 B_dat_o, /* data origin from file header */
24 B_bss_o, /* bss origin from file header */
25 B_txt_l, /* text length from file header */
26 B_dat_l, /* data length from file header */
27 B_bss_l, /* bss length from file header */
28 B_lod_l; /* total data length checked */
29
30long B_end; /* end address */
31
32/*
33 */
34
35/*
36 ============================================================================
37 lstat(fn) -- stat an object file named by string 'fn'.
38 ============================================================================
39*/
40
41lstat(fn)
42char *fn;
43{
44 register long i, bgnbss, endbss, total_l;
45
46 /* initialize the origins and lengths to 0 */
47
48 B_txt_o = 0L;
49 B_dat_o = 0L;
50 B_bss_o = 0L;
51 B_txt_l = 0L;
52 B_dat_l = 0L;
53 B_bss_l = 0L;
54 B_lod_l = 0L;
55
56 /* open the file */
57
58 if (NULL EQ (B_file = fopenb(fn, "r"))) {
59
60 printf("sizes: Unable to open \"%s\"\n", fn);
61 return(1);
62 }
63
64 /* read in the file header */
65
66 if (1 NE fread(&B_fhdr, sizeof B_fhdr, 1, B_file)) {
67
68 printf("sizes: Unable to read header for \"%s\"\n", fn);
69 fclose(B_file);
70 return(2);
71 }
72
73 /* check the magic */
74
75 if ((B_fhdr.F_Magic NE F_R_C) AND (B_fhdr.F_Magic NE F_R_D)) {
76
77 printf("sizes: Bad magic [$%04x] in file \"%s\"\n",
78 B_fhdr.F_Magic, fn);
79
80 fclose(B_file);
81 return(3);
82 }
83
84/*
85
86*/
87
88 /* if it's a discontinuous file, read the origins */
89
90 if (B_fhdr.F_Magic EQ F_R_D) {
91
92 B_dat_o = getl(B_file);
93 B_bss_o = getl(B_file);
94 }
95
96 B_txt_o = B_fhdr.F_Res2;
97 B_lod_l = B_fhdr.F_Text + B_fhdr.F_Data;
98
99 fclose(B_file);
100
101 B_txt_l = B_fhdr.F_Text;
102 B_dat_l = B_fhdr.F_Data;
103 B_bss_l = B_fhdr.F_BSS;
104 B_end = B_txt_o + B_lod_l - 1L;
105
106 if (B_bss_o)
107 bgnbss = B_bss_o;
108 else
109 bgnbss = B_end + 1L;
110
111 endbss = bgnbss + B_bss_l - 1L;
112
113 printf("File \"%s\" is a %s loaded file and\n",
114 fn, (B_fhdr.F_Magic EQ F_R_D) ? "Scatter" : "Contiguously");
115
116 printf("loads from $%08lx to $%08lx (%ld bytes)\n",
117 B_txt_o, B_end, B_lod_l);
118
119 printf(" with BSS $%08lx to $%08lx (%ld bytes)\n\n",
120 bgnbss, endbss, B_bss_l);
121
122 printf(" B_txt_o = $%08lx, B_dat_o = $%08lx, B_bss_o = $%08lx\n",
123 B_txt_o, B_dat_o, B_bss_o);
124
125 printf(" B_txt_l = $%08lx, B_dat_l = $%08lx, B_bss_l = $%08lx\n\n",
126 B_txt_l, B_dat_l, B_bss_l);
127
128 total_l = B_txt_l + B_dat_l + B_bss_l;
129
130 printf("Total program length = %ld ($%08lx) bytes\n",
131 total_l, total_l);
132
133 return(0);
134}
135
136/*
137
138*/
139
140main(argc, argv)
141int argc;
142char *argv[];
143{
144 int rc;
145
146 if (argc NE 2) {
147
148 printf("sizes: ERROR - file name required\n");
149 exit(1);
150 }
151
152 if (lstat(argv[1]))
153 exit(1);
154 else
155 exit(0);
156}
Note: See TracBrowser for help on using the repository browser.