home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
gdead.berkeley.edu
/
gdead.berkeley.edu.tar
/
gdead.berkeley.edu
/
pub
/
cad-tools
/
m36gen.tar
/
m36gen_dir
/
m36gen.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-01-08
|
8KB
|
435 lines
#include <stdio.h>
#include "getbox.c"
#define PLACES 4
#define E_NL '\012'
#define NIL (layer_desc *) 0
typedef struct layer_desc {
char name[5];
int flashs;
int file_no;
struct layer_desc *next;
} layer_desc;
layer_desc *layer_list, *read_dir();
extern char *bin_lib_name;
char *getlogin();
int x_trans = 0, /* the amount the masks are to be translated in
* in the x direction
*/
y_trans = 0; /* the amount the masks are to be translated in
* in the y direction
*/
char *dir_file;
int x_center,y_center;
int left, right, top, bottom; /* the bounding box for the masks */
int silent = 0;
int debug = 0;
int center = 0;
int one_pass = 0;
char *name;
int command_number = 1;
FILE *null_file, *tty, *infile;
/*
* m36gen reads the output of ciftomann, creates a directory
* of the various masks and converts it to David Mann 3600 format.
* It then ouputs the information to pg_write which writes
* the information in the proper format on a mag tape.
*
* In addition, m36gen will center the masks at
* any location the user chooses.
*/
main(argc,argv)
int argc;
char **argv;
{
/* char layer_name[5]; */
char layer_name[11];
char line_buffer[500];
layer_desc *current;
int finished;
int file_no;
int first, first_flash;
int o_x, o_y, o_w, o_l, o_a;
int i;
char *ptr;
/* remind user that there is a terminal by the tape drive */
if(strcmp("/dev/ttya", ttyname(0))) {
fprintf(stderr, "Reminder: there is a terminal next to the tape drive!\n\n");
}
tty = fopen("/dev/tty", "r");
name = getlogin();
/* input the command line arguments */
if(get_args(argc,argv) < 0){
exit(0);
}
for (ptr=name; *ptr != '\0'; ptr++) {
if (*ptr >= 'a' && *ptr <= 'z') {
*ptr += 'A' - 'a';
}
}
if (!one_pass) {
finished = 0;
first = 1;
/*
* Make one pass through to build up the directory
*/
do {
register int c;
flush_space(infile,c);
switch(c) {
case '(' :
flush_comment();
break;
case 'L' :
if (first == 1) {
layer_list = (layer_desc *) malloc(sizeof(layer_desc));
current = layer_list;
first = 0;
} else {
current->next = (layer_desc *) malloc(sizeof(layer_desc));
current = current->next;
}
if (fscanf(infile," %5[^ ;]",current->name) != 1) {
/* if (fscanf(infile," %10s",current->name) != 1) { */
error("Bad Layer name in code");
}
current->flashs = 0;
current->next = NIL;
flush_to_semi();
break;
case 'B' :
if ( center ) {
int params;
int l,w,x,y,x_dir,y_dir;
params = get_box(infile, &l, &w, &x, &y, &x_dir,
&y_dir);
if ( params != 4 && params != 6 ) {
error("Bad box command");
}
update_bb(l,w,x,y);
} else {
flush_to_semi();
}
/*printf(" flash\n"); */
current->flashs++;
break;
case 'E' :
finished = 1;
break;
default :
error("Unrecognizable command in input");
}
command_number++;
} while ( !finished );
rewind(infile);
} else {
layer_list = read_dir(dir_file);
}
/*
* Write the directory onto the tape
*/
fprintf(stderr,"Hit return when the tape is ready : ");
getc(tty);
if ( !silent ) {
fprintf(stderr,"\nWriting the directory\n");
}
start_write();
file_no = 1;
for ( current = layer_list; current != NIL; current = current->next){
current->file_no = file_no;
sprintf(line_buffer,"%-6.6s%-6.6s.T%02d0000",name,current->name,
file_no);
put_string(line_buffer);
file_no++;
if (file_no%25 == 1) {
put_string(" "); /* start a new record */
}
}
put_string("$");
stop_write();
if ( !silent ) {
fprintf(stderr, "\n");
}
if ( center ) {
x_trans = x_center - ( right + left )/2;
y_trans = y_center - ( top + bottom )/2;
printf("x_trans: %d\ty_trans: %d\n", x_trans, y_trans);
}
finished = 0;
first = 1;
command_number = 1;
current = layer_list;
/*
now process the file layer by layer, producing a seperate
file for each layer
*/
do {
register int c;
flush_space(infile, c);
switch(c) {
case '(' :
flush_comment();
break;
case 'L' :
if (fscanf(infile," %5[^ ;]",layer_name) != 1) {
/* if (fscanf(infile," %10s",layer_name) != 1) { */
error("Bad Layer name in code");
}
if (first == 1) {
first = 0;
current = layer_list;
} else {
current = current->next;
put_string("$"); /* mark the end of the mask */
stop_write(); /* end the previous mask */
}
if (current == (layer_desc *) 0 ||
strncmp(current->name, layer_name, strlen(layer_name)) != 0) {
fprintf(stderr, "Layer %s is out of order or not in the directory.\nNo more layers will be written\n", layer_name);
exit(-1);
}
if ( !silent ) {
fprintf(stderr,"Starting layer %s\n",layer_name);
fprintf(stderr,"This layer contains %d flashes\n\n",
current->flashs);
}
start_write(); /* start the mask for this
layer */
sprintf(line_buffer,
"#\"%02d%c", current->file_no, E_NL);
put_string(line_buffer);
put_record();
sprintf(line_buffer, "\"T3600 FILE %s %s %d FLASHES IN THIS FILE%c",
name, layer_name, current->flashs, E_NL);
put_string(line_buffer);
first_flash = 1;
flush_to_semi();
break;
case 'B' :
{
int params, tmp, angle;
int l,w,x,y,x_dir,y_dir;
params = get_box(infile, &l, &w, &x, &y, &x_dir,
&y_dir);
if ( params != 4 && params != 6 ) {
error("Bad box command");
}
x += x_trans;
y += y_trans;
if (params == 6) {
angle = dir_to_angle(x_dir, y_dir);
if (angle > 900) {
/* swap width for length */
angle -= 900;
tmp = w; w = l; l = tmp;
}
} else {
angle = 0;
}
if (first_flash) {
first_flash = 0;
o_x = x; o_y = y, o_l = l; o_w = w; o_a = angle;
put_string("X");
put_int(x, PLACES);
put_string("Y");
put_int(y, PLACES);
put_string("H");
put_int(w, PLACES);
put_string("W");
put_int(l, PLACES);
put_string("A");
put_int(angle, 1);
} else {
if (o_x != x) {
put_string("X");
put_int(x, PLACES);
o_x = x;
}
if (o_y != y) {
put_string("Y");
put_int(y, PLACES);
o_y = y;
}
if (o_w != w) {
put_string("H");
put_int(w, PLACES);
o_w = w;
}
if (o_l != l) {
put_string("W");
put_int(l, PLACES);
o_l = l;
}
if (o_a != angle) {
put_string("A");
put_int(angle, 1);
o_a = angle;
}
}
put_string(";");
break;
}
case 'E' :
finished = 1;
break;
default :
error("Unrecognizable command in input");
}
command_number++;
} while ( !finished );
put_string("$"); /* mark the end of the mask */
stop_write();
if ( !silent ) {
fprintf(stderr,"Done !\n");
}
}
layer_desc *read_dir(dir_file)
char *dir_file;
{
FILE *dir;
int retcode, flashes;
char name[100];
layer_desc *current, *list;
dir = fopen(dir_file, "r");
if (dir == NULL) {
perror(dir_file);
exit(-1);
}
retcode = fscanf(dir, "%d %d %d %d", &left, &bottom, &right, &top);
if (retcode != 4) {
fprintf(stderr, "%s : Bad format for a directory file\n",
dir_file);
exit(-1);
}
current = (layer_desc *) 0;
while ( (retcode = fscanf(dir, "%s %d", name, &flashes)) != EOF) {
if (current == (layer_desc *) 0) {
list = current = (layer_desc *) malloc(sizeof(layer_desc));
} else {
current->next = (layer_desc *) malloc(sizeof(layer_desc));
current = current->next;
}
if (retcode != 2) {
fprintf(stderr, "%s : Bad format for a directory file\n",
dir_file);
exit(-1);
}
strncpy(current->name, name, 5);
current->flashs = flashes;
/* printf("changing flashes\n"); */
current->next = (layer_desc *) 0;
}
if (current == (layer_desc *) 0) {
fprintf(stderr, "%s: No layers in directory file\n", dir_file);
exit(-1);
}
return(list);
}