Exemple #1
0
    int renameGi_name(char *str1,char *str2)
      {
       struct gi_tab *p;
       struct display_tab *pd;
       struct iso *piso;

       if (str2==NULL || strprt(str2)==0 || str1==NULL || strprt(str1)==0)
							return 0;

       if (strcmp(str1,Gi_tab.name) == 0)
	 {
	  err_warn(1,fperr,
	   "Error - The default Graphics Isolines (Gi_%s) can't be renamed.\n",
								str1);
	  return 0;
	 }
       if (strcmp(str2,Gi_tab.name) == 0)
	 {
	  err_warn(1,fperr,
	    "Error - Can't rename (Gi_%s) to the default Isolines (Gi_%s).\n",
								str1,str2);
	  return 0;
	 }

       for (pd=&D_tab;pd != NULL; pd=pd->next)
	 {
	  if (!(pd->off) && strcmp(pd->g_name,str1) == 0)
	    {
	     err_warn(1,fperr,
	"Error - Graphics Isolines (Gi_%s) is in use.  Can't rename (Gi_%s).\n",
								str2,str1);
	     return 0;
	    }
	 }

       for (p=&Gi_tab;p != NULL;p=p->next)
	 {
	  if (strcmp(str2,p->name) == 0)
	    {
	     err_warn(1,fperr,
	 "Error - Can't rename Graphics Isolines (Gi_%s) to existing (Gi_%s)\n",
							str1,str2);
	     return 0;
	    }
	 }
      for (p=&Gi_tab;p != NULL;p=p->next)
	 {
	  if (strcmp(str1,p->name) == 0)
	    {
	     strcpy(p->name,str2);
	     if (!Inactive && fpout != NULL)
			fprintf(fpout,"RENAME(Gi_%s,Gi_%s)\n",str1,str2);
	     return 1;
	    }
	 }
       err_warn(1,fperr,
	"Error - Graphics Isolines (Gi_%s) can't be found to rename.\n",
						str1);
       return 0;
      }
Exemple #2
0
static int db_migrate_v1() {
	const char *query;

	aug_log("migrate to schema v1\n");
#define RUN_QM(_query) \
	do { \
		if(sqlite3_exec(g.handle, _query, NULL, NULL, NULL) != SQLITE_OK) { \
			query = _query; \
			goto rollback; \
		} \
	} while(0)

	if(sqlite3_exec(g.handle, "BEGIN", NULL, NULL, NULL) != SQLITE_OK) {
		query = "BEGIN";
		goto fail;
	}
	RUN_QM(db_qm1_admin);
	RUN_QM(db_qm1_tags);
	RUN_QM(db_qm1_blobs);
	RUN_QM(db_qm1_fk_blobs_tags);
	RUN_QM(db_qm1_admin_populate);
	RUN_QM("COMMIT");
#undef RUN_QM

	return 0;

rollback:
	if(sqlite3_exec(g.handle, "ROLLBACK", NULL, NULL, NULL) != SQLITE_OK)
		err_warn(0, "failed to rollback: %s", sqlite3_errmsg(g.handle));
fail:
	err_warn(0, "failed to execute query %s: %s", query, sqlite3_errmsg(g.handle));
	return -1;
}
Exemple #3
0
static int db_version(int *version) {
	int status;
	sqlite3_stmt *stmt;

	if( (status = sqlite3_prepare_v2(g.handle, db_qs_version, \
			ARRAY_SIZE(db_qs_version), &stmt, NULL)) != SQLITE_OK) {
		if(status == SQLITE_ERROR) { /* sql error => the table doesnt exist */
			*version = 0;
			goto finalize;
		}
		else {
			err_warn(0, "failed to find db version: (%d) %s", status, sqlite3_errmsg(g.handle));
			goto fail;
		}
	}

	if(sqlite3_step(stmt) != SQLITE_ROW) {
		err_warn(0, "failed to get version data from the db: %s", sqlite3_errmsg(g.handle));
		goto fail;
	}

	*version = sqlite3_column_int(stmt, 0);

finalize:
	if(sqlite3_finalize(stmt) != SQLITE_OK) {
		err_warn(0, "failed to finalize statement: %s", sqlite3_errmsg(g.handle));
		return -1;
	}

	return 0;
fail:
	if(sqlite3_finalize(stmt) != SQLITE_OK)
		err_warn(0, "failed to finalize statement: %s", sqlite3_errmsg(g.handle));
	return -1;
}
Exemple #4
0
    struct table_chorn *getTo(char *str)
      {
       struct table_chorn *p,*p1;

/*		Search chorn table for attributes to be copied.	*/

       for (p1=&To_tab;p1 != NULL;p1=p1->next)
	  if (strcmp(str,p1->name) == 0) break;
       if (p1 == NULL)
	 {
	  err_warn(0,fperr,
	   "Warning - Chorn attributes (%s) can't be found for get.\n",str);
	  return NULL;
	 }

/*		Create a new table structure and copy to it.	*/

       if((p=(struct table_chorn *)malloc(sizeof(struct table_chorn)))==NULL)
	 {
	  err_warn(1,fperr,
	    "Error - memory for getting Chorn table (%s) not found.\n",str);
	  return 0;
	 }

       strcpy(p->name,p1->name);
       p->chh=p1->chh;
       p->chua=p1->chua;
       p->chpath=p1->chpath;
       p->chalh=p1->chalh;
       p->chalv=p1->chalv;
       p->next=NULL;

       return p;
      }
Exemple #5
0
static int db_migrate() {
	int version;

	if(db_version(&version) != 0) {
		err_warn(0, "failed to get db version number");
		return -1;
	}
	aug_log("db version: %d\n", version);

	while(version < 2) {
		switch(version) {
		case 0:
			if(db_migrate_v1() != 0)
				return -1;
			break;
		case 1: /* fall through */
			if(db_migrate_v2() != 0)
				return -1;
			break;
		default:
			err_warn(0, "dont know how to migrate from db version %d", version);
			return -1;
		}

		if(db_version(&version) != 0) {
			err_warn(0, "failed to get db version number");
			return -1;
		}
	}

	return 0;
}
Exemple #6
0
    int removeGi_name(char *str)
      {
       struct gi_tab *p,*ptb;
       struct display_tab *pd;
       struct gi_attr *pa;
       struct iso *piso,*piso1;

       if (str == NULL || strprt(str) == 0) return 0;

       if (strcmp(str,Gi_tab.name) == 0)
	 {
	  err_warn(1,fperr,
	    "Error - The default Graphics Isolines (Gi_%s) can't be removed.\n",
								str);
	  return 0;
	 }

       for (pd=&D_tab;pd != NULL; pd=pd->next)
	 {
	  if (!(pd->off) && cmpncs(pd->type,"isoline") == 0 &&
						 strcmp(pd->g_name,str) == 0)
	    {
	     err_warn(1,fperr,
	      "Error - Graphics Isolines (Gi_%s) is in use, not removed.\n",
								str);
	     return 0;
	    }
	 }
       for (p=ptb=&Gi_tab;p != NULL;p=p->next)
	 {
	  if (strcmp(str,p->name) == 0)
	    {
	     ptb->next=p->next;
	     pa=p->pGi_attr;
	     piso1=pa->line;
	     free((char *)pa);
	     while (piso1 != NULL)
	       {
	        piso=piso1->next;
		free((char *) piso1);
		piso1=piso;
	       }
	     free((char *)p);
	     if (!Inactive && fpout != NULL)
			fprintf(fpout,"REMOVE(Gi_%s)\n",str);
	     return 1;
	    }
	  ptb=p;
	 }
       err_warn(1,fperr,
	 "Error - Graphics Isolines (Gi_%s) can't be found to remove.\n",str);
       return 0;
      }
Exemple #7
0
    struct table_text *getTt(char *str)
      {
       struct table_text *p,*p1;

/*		Search text table for attributes to be copied.	*/

       for (p1=&Tt_tab;p1 != NULL;p1=p1->next)
	  if (strcmp(str,p1->name) == 0) break;
       if (p1 == NULL)
	 {
	  err_warn(0,fperr,
	   "Warning - Text attributes (%s) can't be found for get.\n",str);
	  return NULL;
	 }

/*		Create a new table structure and copy to it.	*/

       if((p=(struct table_text *)malloc(sizeof(struct table_text)))==NULL)
	 {
	  err_warn(1,fperr,
	    "Error - memory for getting Text table (%s) not found.\n",str);
	  return 0;
	 }

       strcpy(p->name,p1->name);
       strcpy(p->proj,p1->proj);
       p->txfont=p1->txfont;
       p->txpr=p1->txpr;
       p->txexp=p1->txexp;
       p->txsp=p1->txsp;
       p->txci=p1->txci;
       p->txfci=p1->txfci;
       p->priority=p1->priority;
       p->tvp[0]=p1->tvp[0];
       p->tvp[1]=p1->tvp[1];
       p->tvp[2]=p1->tvp[2];
       p->tvp[3]=p1->tvp[3];
       p->twc[0]=p1->twc[0];
       p->twc[1]=p1->twc[1];
       p->twc[2]=p1->twc[2];
       p->twc[3]=p1->twc[3];
       if (copy_points( &p->tx, p1->tx) == 0) return 0;
       if (copy_points( &p->ty, p1->ty) == 0) return 0;
       if (copy_strings( &p->ts, p1->ts) == 0) return 0;
       p->next=NULL;

       return p;
      }
Exemple #8
0
int TB_connect(int cid)
{
  int r, dummy;
  term *trm, *in_sign, *out_sign;
  assert_valid_cid(cid);
  
  WellKnownSocketPort = connections[cid]->port;
  r = mkports(TBfalse, connections[cid]->tool_name, connections[cid]->host,
	     &connections[cid]->tid, &connections[cid]->socket, &dummy);
  if(r == TB_ERROR) {
    if(connections[cid]->verbose)
      TBmsg("TB_connect: failed to connect to ToolBus port %d\n",
	    connections[cid]->port);
    return -1;
  }

  if(connections[cid]->verbose)
    TBmsg("TB_connect: connected to ToolBus port %d, tid = %d\n",
	  connections[cid]->port, connections[cid]->tid);

  trm = TBread(connections[cid]->socket); /* obtain the tool signature from the ToolBus */

  if(TBmatch(trm, "rec-do(signature(%t,%t))", &in_sign, &out_sign)){
    TBwrite(connections[cid]->socket, TBmake("snd-void()"));
    if(connections[cid]->sigchecker){
      trm = (*connections[cid]->sigchecker)(cid, in_sign);
      if(trm)
	err_warn("TBconnect -- NOT IN INPUT SIGNATURE: %t", trm);
    }
  } else
    err_fatal("signature information garbled: %t", trm);
 
  return 0;
}
Exemple #9
0
int db_init(const char *fpath) {
	if(sqlite3_open(fpath, &g.handle) != SQLITE_OK) {
		err_warn(0, "failed to open sqlite db: %s", sqlite3_errmsg(g.handle));
		goto fail;
	}

	if(db_migrate() != 0) {
		err_warn(0, "failed to migrate db");
		goto fail;
	}

	return 0;

fail:
	sqlite3_close(g.handle);
	return -1;
}
Exemple #10
0
    struct table_line *getTl(char *str)
      {
        float			deflt=1.0;
        struct table_line 	*p,*p1;
        extern int		copy_points();

/*		Search line table for attributes to be copied.	*/

       for (p1=&Tl_tab;p1 != NULL;p1=p1->next)
	  if (strcmp(str,p1->name) == 0) break;
       if (p1 == NULL)
	 {
	  err_warn(0,fperr,
	   "Warning - Line attributes (%s) can't be found for get.\n",str);
	  return NULL;
	 }

/*		Create a new line table structure and copy to it.	*/

       if((p=(struct table_line *)malloc(sizeof(struct table_line)))==NULL)
	 {
	  err_warn(1,fperr,
	    "Error - memory for getting Line table (%s) not found.\n",str);
	  return 0;
	 }

       strcpy(p->name,p1->name);
       strcpy(p->proj,p1->proj);
       copy_int_array( &p->ltyp, &p1->ltyp, &p->ltyp_size, p1->ltyp_size, 1 );
       copy_float_array( &p->lwsf, &p1->lwsf, &p->lwsf_size, p1->lwsf_size, &deflt );
       copy_int_array( &p->lci, &p1->lci, &p->lci_size, p1->lci_size, 241 );
       p->priority=p1->priority;
       p->lvp[0]=p1->lvp[0];
       p->lvp[1]=p1->lvp[1];
       p->lvp[2]=p1->lvp[2];
       p->lvp[3]=p1->lvp[3];
       p->lwc[0]=p1->lwc[0];
       p->lwc[1]=p1->lwc[1];
       p->lwc[2]=p1->lwc[2];
       p->lwc[3]=p1->lwc[3];
       if (copy_points( &p->lx, p1->lx) == 0) return 0;
       if (copy_points( &p->ly, p1->ly) == 0) return 0;
       p->next=NULL;

       return p;
      }
Exemple #11
0
    int removeGfo_name(char *str)
      {
       struct gfo_tab *p,*ptb;
       struct display_tab *pd;

       if (str == NULL || strprt(str) == 0) return 0;

       if (strcmp(str,Gfo_tab.name) == 0)
	 {
	  err_warn(2,fperr,
	      "Error - Can't remove the default Fill Outlines (Gfo_%s).\n",str);
	  return 0;
	 }

       for (pd=&D_tab;pd != NULL; pd=pd->next)
	 {
	  if (!(pd->off) && cmpncs(pd->type,"outfill") == 0 &&
						 strcmp(pd->g_name,str) == 0)
	    {
	     err_warn(1,fperr,
	      "Error - Fill Outlines (Gfo_%s) is in use, not removed.\n",str);
	     return 0;
	    }
	 }
       for (ptb=p=&Gfo_tab;p != NULL;ptb=p,p=p->next)
	 {
	  if (strcmp(str,p->name) == 0)
	    {
	     ptb->next=p->next;
	     free((char *)p->pGfo_attr);
	     free((char *)p);
	     if (!Inactive && fpout != NULL)
		fprintf(fpout,"REMOVE(Gfo_%s)\n",str);
	     return 1;
	    }
	 }
       err_warn(1,fperr,
	     "Error - Fill Outlines (Gfo_%s) can't be found to remove.\n",str);
       return 0;
      }
Exemple #12
0
static int db_migrate_v2() {
	const char *query;

	aug_log("migrate to schema v2\n");
#define RUN_QM(_query) \
	do { \
		if(sqlite3_exec(g.handle, _query, NULL, NULL, NULL) != SQLITE_OK) { \
			query = _query; \
			goto rollback; \
		} \
	} while(0)

	if(sqlite3_exec(g.handle, "BEGIN", NULL, NULL, NULL) != SQLITE_OK) {
		query = "BEGIN";
		goto fail;
	}
	RUN_QM( \
		"ALTER TABLE blobs ADD COLUMN " \
		"trash INTEGER NOT NULL ON CONFLICT ROLLBACK DEFAULT 0" \
	);
	RUN_QM(
		"UPDATE admin SET " \
		"version = 2, " \
		"updated_at = strftime('%s', 'now') " \
	);
	RUN_QM("COMMIT");
#undef RUN_QM

	return 0;

rollback:
	if(sqlite3_exec(g.handle, "ROLLBACK", NULL, NULL, NULL) != SQLITE_OK)
		err_warn(0, "failed to rollback: %s", sqlite3_errmsg(g.handle));
fail:
	err_warn(0, "failed to execute query %s: %s", query, sqlite3_errmsg(g.handle));
	return -1;	
}
Exemple #13
0
    int chk_mov_To (struct table_chorn *pt)

      {
       struct table_chorn *ptb,*ptab;

       if (pt == NULL) return 0;
       	for (ptb=ptab=&To_tab;
		ptab!=NULL && cmpnbl(pt->name,ptab->name)!=0;
			ptb=ptab,ptab=ptab->next);

/*		Check if it's trying to overwrite the default.		*/

         if (ptab == &To_tab || ptab == &To_tab1 || ptab == &To_tab2 ||
	     ptab == &To_tab3 || ptab == &To_tab4 )
	  {
	   err_warn(1,fperr,"Error - can't replace the defaults (To_%s).\n",
				pt->name);
	   free((char *)pt);
	   return 0;
	  }

	if (ptab == NULL)
	  {
	   ptb->next=ptab=pt;
	  }
	else
	  {
/* 	    if (pt->chh != ptab->chh) printf("chh diff %f,%f\n",pt->chh, ptab->chh); */
/* 	   if (pt->chua != ptab->chua) printf("cua diff\n"); */
/* 	   if (pt->chpath != ptab->chpath) printf("chpath diff\n"); */
/* 	   if (pt->chalh != ptab->chalh) printf("chalh diff %d,%d\n",pt->chalh, ptab->chalh); */
/* 	   if (pt->chalv != ptab->chalv) printf("chalv diff\n"); */
	   if (pt->chh != ptab->chh || pt->chua != ptab->chua ||
	       pt->chpath != ptab->chpath || pt->chalh != ptab->chalh ||
	       pt->chalv != ptab->chalv)
	     {
	      ptab->chh=pt->chh;
	      ptab->chua=pt->chua;
	      ptab->chpath=pt->chpath;
	      ptab->chalh=pt->chalh;
	      ptab->chalv=pt->chalv;
	      check_d_chorn(ptab->name);
	     }
	   free((char *)pt);
	   pt=NULL;
	  }
	if (!Inactive && fpout != NULL) prtTo(fpout,ptab);
	return 1;
       } 
Exemple #14
0
static int read_from_any_channel(inport **inp)
{
  int i, nelem, error;
  fd_set read_template;

retry:
  FD_ZERO(&read_template);
  for(i = 0; i < ninports; i++){
    if(inportset[i].in >= 0 && !inportset[i].suspended)
      FD_SET(inportset[i].in,&read_template);
  }
  /* TBmsg("read_from_any_channel, before select\n"); */
  if((error = select(FD_SETSIZE, &read_template,
                     NULL, NULL, NULL)) >= 0){

    for(i = 0; i < ninports; i++){
      if(inportset[i].in >= 0 && 
	 FD_ISSET(inportset[i].in,&read_template)) {
	/* TBmsg("read_from_any_channel, data on port %d\n", inportset[i].in); */
        if(inportset[i].in == 0){
          nelem = read_from_stdin();
	} else if(inportset[i].term_port == TBfalse){
	  *inp = &inportset[i];
	  return 0;
        } else {
          nelem = multi_read(inportset[i].in);
	}
        if(nelem == 0){
          err_warn("lost connection with ToolBus");
	  exit(-1);
          }
        if(nelem < 0){
          err_sys_fatal("read failed"); /**************/
          goto retry;
        }
        *inp = &inportset[i];
        return nelem;
      }
    }
  } else {
    if(errno != EINTR)
      err_sys_warn("select failed");
    goto retry;
  }
  return TB_ERROR;
}
Exemple #15
0
static term *tool_read_term(void)
{
  int nelem;
  term *trm, *rtrm;
  inport *inp;
  TBbool sndvoid = TBfalse;

  while(TBtrue){
    if(stand_alone){
      fprintf(stdout, "%s", single_prompt);
      fflush(stdout);
    }
    inp = NULL;
    nelem = read_from_any_channel(&inp);
    if(nelem < 0){
      err_warn("tool_read_term: cannot find ready input channel");
      continue;
    }
    if(inp && inp->term_port){
      if((trm = parse_buffer())){
	/*TBmsg("tool_read_term: ***%t***\n", trm);*/
	if(streq(get_txt(fun_sym(trm)), "rec-do"))
          sndvoid = TBtrue;
	rtrm = (*inp->callbackTerm)(trm);
	if(sndvoid)
	  return Snd_Void;
	else
	  return rtrm;
      }
    } else {
      if(inp)
	return (*inp->callbackChar)(inp->in);
    } 
  }
  return NULL; /* <PO> missing return from lcc */
}
Exemple #16
0
    int 
    vcs_main()
	/*int argc;   No longer needed for Python interface
	char *argv[];*/
      {
/*		This program is a test for later development of script
		processing.						*/
        int argc = 0;
        char **argv = NULL;

	char *getenv();
	FILE *fopen(), fpcdat;
	int i,j,k;
	int got_font_or_geom = 0;
        float fv=1.0;
	char *ptri, *ptro;
	int mode=0777;
        char str[2], buf[1024];
	char logo_data2[388680];
	struct display_tab *dtab;
        extern struct table_line Tl_tab;
        extern struct table_mark Tm_tab;
        extern struct table_fill Tf_tab;
	extern struct table_FT_VCS_FONTS TTFFONTS;
	struct table_FT_VCS_FONTS  *current_font;
	
	int *pi;
        static int read_initial_attribute = 0;
	FILE *logo_file,*logo_file2;
	char c;

/*        f_init();
*/
/*			Additional initialization for the 'default' 	*/
/*			line, marker and fillarea secondary attributes	*/
        get_int_size_and_set_value( &Tl_tab.ltyp, 1, (int)1 );   Tl_tab.ltyp_size=1;
        get_float_size_and_set_value( &Tl_tab.lwsf, 1, &fv );    Tl_tab.lwsf_size=1.0;
        get_int_size_and_set_value( &Tl_tab.lci, 1, (int)1 );  Tl_tab.lci_size=1;
        get_int_size_and_set_value( &Tm_tab.mtyp, 1, (int)1 );   Tm_tab.mtyp_size=1;
        get_float_size_and_set_value(&Tm_tab.msize, 1, &fv);     Tm_tab.msize_size=1.0;
        get_int_size_and_set_value( &Tm_tab.mci, 1, (int)1 );  Tm_tab.mci_size=1;
        get_int_size_and_set_value( &Tf_tab.fais, 1, (int)1 );   Tf_tab.fais_size=1;
        get_int_size_and_set_value( &Tf_tab.fasi, 1, (int)1 );   Tf_tab.fasi_size=1;
        get_int_size_and_set_value( &Tf_tab.faci, 1, (int)1 ); Tf_tab.faci_size=1;
	/* Use extended name lengths at cddrs interface */
	cw_set_string_option(CW_EXTENDED);

/*			Find a base directory.				*/

	if ((base_dir=getenv(DOT_DIRECTORY_ENV)) == NULL)
	  {
	   if ((base_dir=getenv("HOME")) == NULL || strlen(base_dir) ==0) {
               strcpy(dirbase,"./");
               strcat(dirbase,DOT_DIRECTORY);
           }
	   else 
	     {
	      strcpy(dirbase,base_dir);
	      strcat(dirbase,"/");
	      strcat(dirbase,DOT_DIRECTORY);
	     }
	  }
	else  strcpy(dirbase,base_dir);
	base_dir=dirbase;
	
	if (mkdir(base_dir,mode) != 0 && errno != EEXIST)
	  {
	   printf ("Error - you don't have a base directory.\n");
	   printf ("The environment variable");
           printf (DOT_DIRECTORY_ENV);
	   printf (" or HOME needs to be set!\n");
	   return 0;
	  }

	/* First time around add user's home to path of fonts */
	if (read_initial_attribute==0)
	  {
	    /* logo stuff */
	    logo = cairo_image_surface_create_for_data(&logo_data[0],logo_format,logo_width,logo_height,logo_stride);
	    logo_p = cairo_pattern_create_for_surface(logo);
	    i = FT_Init_FreeType( &ft_library );
	    if (i!=0)
	      {
		err_warn(1,fperr,"Error - could not load the FT library!\n");
		return 0;
	      }
	    current_font = &TTFFONTS;
	    while (current_font!=NULL)
	      {
		strcpy(font_file,base_dir);
		strcat(font_file,"/");
		strcat(font_file,current_font->path);
		strcpy(current_font->path,font_file);
		/* add code here to check it actually exists ? */
		current_font=current_font->next;
	      }
	  }
	strcpy(script_file,base_dir);
	strcat(script_file,"/");
	strcat(script_file,"initial.attributes");

	fpin=fpout=fperr=NULL;
	ptri=ptro=ptre=NULL;

	if (argc >= 2)
	  {
	   for (i=1; i < argc; i++)
	     {
	      if (strncmp (argv[i],"-e",2) == 0)
	        {
		 if (strlen(argv[i]) > (size_t)2) j=2;
		 else if (++i < argc) j=0;
		 else return -1;
		 ptre=argv[i];
		 ptre+=j;
		 if ((strchr(ptre,'/')==NULL) && base_dir != NULL)
		   {
		    strcpy(error_file,base_dir);
		    strcat(error_file,"/");
		    strcat(error_file,ptre);
		   }
		 else strcpy(error_file,ptre);
		 ptre=error_file;
		}
	     }
	  }

	if (ptre != NULL && (fperr=fopen(ptre,"w")) == NULL)
	  {
	   printf ("****Error opening error message file:  %s \n",ptre);
	   return -1;
	  }
	else if (ptre == NULL)
	  {
	   if (base_dir != NULL)
	     {
	      strcpy(error_file,base_dir);
	      strcat(error_file,"/");
	      strcat(error_file,errf);
	     }
	   else
	     strcpy(error_file,errf);

	   ptre=error_file;
	   if ((fperr=fopen(ptre,"w"))==NULL)
	     {
	      printf ("****Error opening default error message file:  %s\n",
					ptre);
	      return -1;
	     }
	  }

	/* First of all initialize the FT library */
/*			open GKS 					*/
        gopks(fperr,0);

/*		Read the initial attributes script if is exists.	*/

	if (access(script_file,R_OK) < 0)
	  {
	   printf("Warning - no initial.attributes file.\n");
	  }
	else
	  {
	   if (fperr == NULL) fperr=stdout;
           /* For normalization purposes, only read in the initial attribute one time, since 
            * there may be templates that are already normalized...
            */
           if (read_initial_attribute == 0) k=rscript();
           read_initial_attribute = 1;
	   if (k == 0) err_warn(1,fperr,
		"Error - from read of initial attributes: %d\n",k);
	   if (fpin != NULL)
	      fclose(fpin);
	  }

	script_file[0]='\0';

	fpin=fpout=NULL;
	ptri=ptro=ptre=NULL;

	if (argc >= 2)
	  {
	   for (i=1; i < argc; i++)
	     {
	      if (strncmp (argv[i],"-i",2) == 0)
	        {
                 do_interactive = 1;
		 if (strlen(argv[i]) > (size_t)2) j=2;
		 else if (++i < argc) j=0;
		 else return -1;
		 ptri=argv[i];
		 ptri+=j;
		 if (strncmp("./",ptri,2) == 0) ptri+=2;
		 if (strchr(ptri,'/')==NULL)
		   {
		    get_a_path(script_file);
		    strcat(script_file,"/");
		    strcat(script_file,ptri);
		   }
		 else strcpy(script_file,ptri);
		 ptri=script_file;
		}
	      else if (strncmp (argv[i],"-ni",3) == 0)
	        {
                 do_interactive = 0;
		 if (strlen(argv[i]) > (size_t)3) j=3;
		 else if (++i < argc) j=0;
		 else return -1;
		 ptri=argv[i];
		 ptri+=j;
		 if (strncmp("./",ptri,3) == 0) ptri+=3;
		 if (strchr(ptri,'/')==NULL)
		   {
		    get_a_path(script_file);
		    strcat(script_file,"/");
		    strcat(script_file,ptri);
		   }
		 else strcpy(script_file,ptri);
		 ptri=script_file;
		}
	      else if (strncmp (argv[i],"-o",2) == 0)
	        {
                 do_interactive = 1;
		 if (strlen(argv[i]) > (size_t)2) j=2;
		 else if (++i < argc) j=0;
		 else return -1;
		 ptro=argv[i];
		 ptro+=j;
		 if ((strchr(ptro,'/')==NULL) && base_dir != NULL)
		   {
		    strcpy(output_file,base_dir);
		    strcat(output_file,"/");
		    strcat(output_file,ptro);
		   }
		 else strcpy(output_file,ptro);

/*			Put a ".scr" extension on the name if needed.	*/

		 if ( (j=strlen(ptro)) < 4 || strcmp(".scr",&ptro[j-4]) != 0)
		   {
		    strcat(output_file,".scr");
		   }
		 ptro=output_file;
		}
	      else if (strncmp (argv[i],"-e",2) == 0)
	        {
                 do_interactive = 1;
		 printf ("Error file is:  %s.\n",argv[i]);
		}
	      else if (strncmp (argv[i],"-geom",5) == 0)
	        {
                 do_interactive = 1;
	         got_font_or_geom = 1;
		}
	      else if (strncmp (argv[i],"-quiet",6) == 0)
	        {
                 do_interactive = 1;
		}
	      else if (strncmp (argv[i],"-font",5) == 0)
	        {
                 do_interactive = 1;
	         got_font_or_geom = 1;
		}
	      else
		{
	         if (got_font_or_geom == 0)
		    printf ("Argument %s not used.\n",argv[i]);
	         got_font_or_geom = 1;
		}
	     };
	  };

	if (ptro != NULL && (fpout=fopen(ptro,"w")) == NULL)
	  {
/*   printf("script_file1 = %s\n", script_file);*/
	   printf ("****Error opening script output file:  %s \n",ptro);
	   return -1;
	  }
	if (fpout != NULL) fprintf(fpout,"canvas(open)\n");

/*			Open Workstation Independent Segment Storage.	*/

	gopwk(7,NULL,"WISS");

	gacwk(7);

	gsclip(GNOCLIP);


/*		If there is an input file defined,
		read and process the script.				*/

	strcpy(buf, script_file);
	if ((ptri != NULL) && (k=run_script() == 0)) {
/*   printf("script_file2 = %s\n", script_file);*/
	   printf ("****Error opening script output file:  %s \n",buf);
	} 

	return 0;
      }
Exemple #17
0
int procCanvas(char *str, Gconid_X_drawable **connect_id_in, int canvas_id, double ratio, char *gui, int *tok)
      {
       int i, found=0;
       Gintlist wsid;
       Gconid_X_drawable *connect_id;
       int *pid;
	struct workstations *w;
	int tokm;
	int c=1;
	char strm[256];
#ifdef QTWM
	extern  void vcs_legacy_Qt_open_window(Gconid_X_drawable *connect_id);
#endif
      connect_id = (Gconid_X_drawable *)connect_id_in;
      if (*tok != -99) {
	if (*tok != '(')
	  {
	   err_warn(1,fperr,
		"Error - (CANVAS) not a proper token (%c).\n",*tok);
	   return 0;
	  }
	c=getsttk(strm,&tokm);
	if (tokm != ')')
	  {
	   err_warn(1,fperr,
		"Error - not a proper token (%s%c%s%c).\n",str,*tok,strm,tokm);
	   return 0;
	  }
      }

	/* Copy the command from str to strm */
	strcpy(strm, str);

	/* DNW and CD not checking against w->id anylonger it was set incorrectly when opening multile ws */
	for (w=&Wkst[0]; cmpncs(w->type,"X_WIN") != 0;w++);
	//	for (w=&Wkst[0];w->id != 0 && cmpncs(w->type,"X_WIN") != 0;w++);
	if (w->id == 0)
	  {
	   err_warn(0,fperr,"Warning - X_WIN not available.\n");
	   return 1;
	  }

	if (c > 0 && cmpncs(strm,"close") == 0)
	  {
	    shutdown(connect_id, w->id);
	   return 1;
	  }


/*		Check whether it's open already.			*/

        wsid.number = 0;
        wsid.integers = NULL;
        gqopwk(&wsid);
        for (i=0,pid=wsid.integers;i<wsid.number;pid++,i++)
	  /* DNW and CD use to check against w->id but it is wrong when multiple ws open */
           if (*pid == connect_id->wkst_id) {
	      found = 1;
	      break;
	   }

#ifdef PYTHON
#ifdef X11WM
/* 			CDAT can open as many window as it needs. 	*/
	if (connect_id->display == NULL)
	       connect_id->display=XOpenDisplay(NULL);
#elif defined(QTWM)
/* 	fprintf(stderr,"proc open first, id: %i, %i\n",connect_id,connect_id->wkst_id); */
	vcs_legacy_Qt_open_window_by_id(connect_id->wkst_id);
#else
	fprintf(stderr,"insert your WM open win function here\n");
#endif
	if (!found) {
	  config_canvas(w->id,connect_id,canvas_id,Page.page_orient,gui,ratio);}

#else
/*			If it isn't open, open it.			*/
	if (i == wsid.number)
	  {
	   if (connect_id->display == NULL)
	       connect_id->display=XOpenDisplay(NULL);
           fprintf(stderr,"YAHOOO! %i, %f\n",connect_id,ratio);
	   config_canvas(w->id, connect_id, canvas_id,Page.page_orient,gui,ratio);
	  }
#endif

	if (wsid.number > 0 && wsid.integers != NULL)
	    free((char *)wsid.integers);
	return 1;
      }
Exemple #18
0
    struct gfo_tab *getGfo(char *str)
      {
       int i;
       struct gfo_tab *p,*p1;
       struct gfo_attr *pa,*pa1;

/*		Search outline table for attributes to be copied.	*/

       for (p1=&Gfo_tab;p1 != NULL;p1=p1->next)
	  if (strcmp(str,p1->name) == 0) break;
       if (p1 == NULL || p1->pGfo_attr == NULL)
	 {
	  err_warn(0,fperr,
	 "Warning - Graphics fill outlines (%s) can't be found for get.\n",str);
	  return 0;
	 }
       pa1=p1->pGfo_attr;

/*		Create a new table structure and copy to it.	*/

       if((p=(struct gfo_tab *)malloc(sizeof(struct gfo_tab)))==NULL)
	 {
	  err_warn(1,fperr,
	   "Error - memory for getting Graphics fill outlines(%s) not found.\n",
						str);
	  return NULL;
	 }

       strcpy(p->name,p1->name);

/*		Create a new attribute structure and copy to it.	*/

       if((pa=(struct gfo_attr *)malloc(sizeof(struct gfo_attr)))==NULL)
	 {
	  err_warn(1,fperr,
	   "Error - memory for getting Graphics fill outlines(%s) not found.\n",
						str);
	  free((char *) p);
	  return NULL;
	 }
       p->pGfo_attr=pa;
       strncpy(pa->proj,pa1->proj,256); pa->proj[255] = '\0';
       strncpy(pa->xtl1,pa1->xtl1,256); pa->xtl1[255] = '\0';
       strncpy(pa->xtl2,pa1->xtl2,256); pa->xtl2[255] = '\0';
       strncpy(pa->xmt1,pa1->xmt1,256); pa->xmt1[255] = '\0';
       strncpy(pa->xmt2,pa1->xmt2,256); pa->xmt2[255] = '\0';
       strncpy(pa->ytl1,pa1->ytl1,256); pa->ytl1[255] = '\0';
       strncpy(pa->ytl2,pa1->ytl2,256); pa->ytl2[255] = '\0';
       strncpy(pa->ymt1,pa1->ymt1,256); pa->ymt1[255] = '\0';
       strncpy(pa->ymt2,pa1->ymt2,256); pa->ymt2[255] = '\0';
       strncpy(pa->timeunits,pa1->timeunits,256); pa->timeunits[255] = '\0';
       for (i=0;i<4;i++) pa->dsp[i]=pa1->dsp[i];
       for (i=0;i<4;i++) pa->idsp[i]=pa1->idsp[i];
       pa->calendar=pa1->calendar;
       if (((strcmp(pa1->xat, "linear") != 0) || (strcmp(pa1->xat, "") == 0)) &&            (strcmp(pa->proj, "linear") == 0) ) {
          strncpy(pa->xat,pa1->xat,17); pa->xat[16] = '\0';
       } else {
          strncpy(pa->xat,"linear",17); pa->xat[16] = '\0';
       }
       if (((strcmp(pa1->yat, "linear") != 0) || (strcmp(pa1->yat, "") == 0)) &&            (strcmp(pa->proj, "linear") == 0) ) {
          strncpy(pa->yat,pa1->yat,17); pa->yat[16] = '\0';
       } else {
          strncpy(pa->yat,"linear",17); pa->yat[16] = '\0';
       }
       pa->n=pa1->n;
       for (i=0;i<pa->n;i++) pa->out[i]=pa1->out[i];
       strncpy(pa->f,pa1->f,17); pa->f[16] = '\0';

       return p;
      }
Exemple #19
0
int save_image (FILE *file)
{
	int 		x_loc,y_loc;
#ifdef X11WM
	Window    	canvas_root_win, child_win;
        XImage		*ximage;
#else
	void *ximage = NULL;
#endif
	char		r[MAX_COLORS],g[MAX_COLORS],b[MAX_COLORS];
	unsigned int	x_width,y_height,border_width,depth;
	int		width, height;
#ifdef X11WM
	int		screen = DefaultScreen(connect_id.display);
	int		scrn_width=DisplayWidth(connect_id.display,screen);
        int		scrn_height=DisplayHeight(connect_id.display,screen);
#else
	int		screen;
	int		scrn_width;
        int		scrn_height;
#endif
	int		x1,y1;

	/* 
 	 * Get allocated memory for the XImage structure and copy the
 	 * canvas window to it.
	 */
	/* Get the application window's position */

#ifdef X11WM
	XRaiseWindow(connect_id.display,connect_id.drawable);
	if (	XGetGeometry(
		connect_id.display,connect_id.drawable, &canvas_root_win,
	   	&x_loc, &y_loc, &x_width, &y_height, &border_width, &depth) == 0
				||
		XTranslateCoordinates(connect_id.display,connect_id.drawable,
		canvas_root_win,0,0,&x1,&y1,&child_win) == False)
	  {
	   err_warn(1,fperr,"Error - getting raster image.\n");
	   return 0;
	  }

	width = x_width;
	height = y_height;

	/* Find the new x location and the width, if necessary. */

	if ((-x1 > width) || (x1 > scrn_width)) {
	   err_warn(1,fperr,"Error - X for getting raster image.\n");
	   return 0;
	  }
	if (x1 < 0)
	  {
	   width=width+x1;
	   x1=0;
	  }
	else if (x1+width > scrn_width)
	  {
	   width=scrn_width-x1;
	  }

	if ((-y1 > height) || (y1 > scrn_height)) {
	   err_warn(1,fperr,"Error - Y for getting raster image.\n");
	   return 0;
	  }
	if (y1 < 0)
	  {
	   height=height+y1;
	   y1=0;
	  }
	else if (y1+height > scrn_height)
	  {
	   height=scrn_height-y1;
	  }

        /* This way is good because the root window will create partially obscure windows.
	 * But this method doesn't work for the Mac which has a rootless window.
         * ximage = XGetImage(cptr->connect_id.display,
                RootWindowOfScreen(DefaultScreenOfDisplay(cptr->connect_id.display)),
                   x1, y1, width, height, XAllPlanes(), ZPixmap);
         */
	ximage = XGetImage(connect_id.display,
		           connect_id.drawable,
                           0, 0, width, height, XAllPlanes(), ZPixmap);
#elif defined QTWM
	vcs_legacy_Qt_window_get_image_by_id(connect_id.wkst_id,&ximage);
#else
	fprintf(stderr,"insert here your WM to get image\n");
#endif
        if (ximage == NULL)
	  {
	   err_warn(1,fperr,"Error - getting raster image.\n");
	   return 0;
	  }
	/* If display has 8 bit color */
#ifdef X11WM
        if (ximage->depth == 8) {
           /* Convert X colors to u_char arrays */
           convert_gks_color(r, g, b);

           /* Save the image and its colormap in a Sun Raster file */
           ras_write_ximage(file,  ximage, r, g, b, MAX_COLORS);
        } else {
           /* Save the image with no colormap in a Sun Raster file */
           ras_write_ximage(file, ximage, NULL, NULL, NULL, 0);
	}
#elif defined QTWM
	ras_write_ximage(file, ximage, NULL, NULL, NULL, 0);
#else
	fprintf(stderr,"insert here your write to ras func\n");
#endif

	/* Print out image information
        print_image_info(x_loc, y_loc, ximage, MAX_COLORS);
	*/

	/* Remove the image from memory */
#ifdef X11WM
        XDestroyImage(ximage);
#elif defined QTWM
	free(ximage);
#else
	fprintf(stderr,"insert here your destroy ximage func\n");
#endif
	return 1;
}
Exemple #20
0
    int copy_Gi_name(char *str1,char *str2)
      {
       int i;
       struct gi_tab *p,*ptb,*p1;
       struct display_tab *pd;
       struct gi_attr *pa,*pa1;
       struct iso *piso,*piso1,*piso2,*pison;

       if (str1==NULL || strprt(str1)==0 || str2==NULL || strprt(str2)==0)
						return 0;

/*		It's an internal copy of isoline descriptions.		*/

       if (strcmp(str1,str2) == 0) return 1;

       if (strcmp(str2,Gi_tab.name) == 0)
	 {
	  err_warn(1,fperr,
	   "Error - Can't copy to the default Graphics Isolines (Gi_%s).\n",
							str2);
	  return 0;
	 }

/*		Is it a copy to an existing Isolines attribute set.	*/

       for (ptb=p=&Gi_tab; p != NULL; ptb=p,p=p->next)
	 if (strcmp(str2,p->name) == 0)
	 {
	  err_warn(1,fperr,
	   "Error - Can't copy Isolines (Gi_%s) to existing (Gi_%s).\n",
							str1,str2);
	  return 0;
	 }

/*		Search Isoline table for attributes to be copied.	*/

       for (p1=&Gi_tab;p1 != NULL;p1=p1->next)
	  if (strcmp(str1,p1->name) == 0) break;

       if (p1 == NULL || p1->pGi_attr == NULL)
	 {
	  err_warn(1,fperr,
	   "Error - Graphics Isolines (Gi_%s) not found for copy.\n",str1);
	  return 0;
	 }
       pa1=p1->pGi_attr;

/*		Create a new attribute structure and copy to it.	*/

       if((pa=(struct gi_attr *)malloc(sizeof(struct gi_attr)))==NULL)
	 {
	  err_warn(1,fperr,
	  "Error - memory for Graphics Isolines (Gi_%s) not found for copy.\n",
								str2);
	  return 0;
	 }
       pa->line=NULL;
       strncpy(pa->proj,pa1->proj,256); pa->proj[255] = '\0';
       strncpy(pa->xtl1,pa1->xtl1,256); pa->xtl1[255] = '\0';
       strncpy(pa->xtl2,pa1->xtl2,256); pa->xtl2[255] = '\0';
       strncpy(pa->xmt1,pa1->xmt1,256); pa->xmt1[255] = '\0';
       strncpy(pa->xmt2,pa1->xmt2,256); pa->xmt2[255] = '\0';
       strncpy(pa->ytl1,pa1->ytl1,256); pa->ytl1[255] = '\0';
       strncpy(pa->ytl2,pa1->ytl2,256); pa->ytl2[255] = '\0';
       strncpy(pa->ymt1,pa1->ymt1,256); pa->ymt1[255] = '\0';
       strncpy(pa->ymt2,pa1->ymt2,256); pa->ymt2[255] = '\0';
       strncpy(pa->timeunits,pa1->timeunits,256); pa->timeunits[255] = '\0';
       for (i=0;i<4;i++) pa->dsp[i]=pa1->dsp[i];
       for (i=0;i<4;i++) pa->idsp[i]=pa1->idsp[i];
       pa->calendar=pa1->calendar;
       strncpy(pa->xat,pa1->xat,17); pa->xat[16] = '\0';
       strncpy(pa->yat,pa1->yat,17); pa->yat[16] = '\0';
       pa->labels=pa1->labels;
       
       for (piso1=pa1->line,pison=NULL;piso1 != NULL;piso1=piso1->next)
	 {
	  if ((pison=(struct iso *)malloc(sizeof(struct iso)))==NULL)
	    {
	     err_warn(1,fperr,
	   "Error - memory for Graphics Isolines (Gi_%s) not found for copy./n",
							str2);
	     piso1=pa->line;
	     free((char *)pa);
	     while (piso1 != NULL)
	       {
		piso=piso1->next;
		free((char *) piso1);
		piso1=piso;
	       }
	     return 0;
	    }
	  if (pa->line == NULL) pa->line=pison;
	  else piso->next=pison;
	  piso=pison;

	  piso->id=piso1->id;
	  piso->p=piso1->p;
	  piso->lev=piso1->lev;
	  piso->incr=piso1->incr;
	  piso->hici=piso1->hici;
	  strncpy(piso->lab,piso1->lab,13); piso->lab[12] = '\0';
	  strncpy(piso->lb,piso1->lb,17); piso->lb[16] = '\0';
	  strncpy(piso->tb,piso1->tb,17); piso->tb[16] = '\0';
	  strncpy(piso->to,piso1->to,17); piso->to[16] = '\0';
	  piso->cw=piso1->cw;
	  piso->ls=piso1->ls;
	  piso->angle=piso1->angle;
	  piso->spc=piso1->spc;
	  piso->next=NULL;
	 }

       if((p=(ptb->next)=(struct gi_tab *)malloc(sizeof(Gi_tab))) == NULL)
	 {
	  err_warn(1,fperr,
	  "Error - memory for Graphics Isolines (Gi_%s) not found for copy.\n",
								str2);
	  piso1=pa->line;
	  free((char *)pa);
	  while (piso1 != NULL)
	    {
	     piso=piso1->next;
	     free((char *) piso1);
	     piso1=piso;
	    }
	  return 0;
	 }
       p->pGi_attr=pa;
       p->next=NULL;
       strcpy(p->name,str2);

       if (!Inactive && fpout != NULL)
		fprintf(fpout,"COPY(Gi_%s,Gi_%s)\n",str1,str2);
       return 1;
      }
Exemple #21
0
    int rscript ()

/*	This function reads and interprets a script.

	Attributes for an array are given following "A_name".

	Values and strings for a list are given following "L_name".

	Return gives:	1 - when an end of file was reached
			0 - if the file was empty or uninterpretable	*/

      {

	int i,c;
	long int    cur_pos;
	char str[STRMAX+1];/* used for a string from the script */
	int tok;	/* used to return a token following the string */
	struct runit *pr,*prm;

/*		This function reads elements of a script and stores the
		attributes defined there.				*/

/*		Check the script isn't already being run (i.e. infinite
		loop) and find pointer to last (pr) and next to last (prm)
		file pointer and script file name.			*/

	for (i=0,prm=pr=&Run;pr!=NULL;i++,pr=pr->next)
	  {
	   if (strcmp(script_file,pr->scr_file) == 0)
	     {
	      err_warn(1,fperr,
		"Error - infinite loop on RUN script file (%s).\n",script_file);
	      script_file[0]='\0';
	      fpin=NULL;

	      while (pr!=NULL) {prm=pr; pr=pr->next;}
	      strcpy(script_file,prm->scr_file);
	      fpin=prm->fpscr;
	      if (prm == &Run)
	        {
	         prm->scr_file[0]='\0';
	         prm->fpscr=NULL;
	        }
	      return 0;
	     }
	   prm=pr;
	  }

/*		Open the input script file.				*/
	if (script_file[0] == '\0' || (fpin=fopen(script_file,"r")) == NULL)
	  {
	   err_warn(1,fperr,
		"Error - opening file (%s) - no script run.\n",script_file);
	   script_file[0]='\0';
	   if (fpin != NULL) fclose(fpin);
	   fpin=NULL;
	   strcpy(script_file,prm->scr_file);
	   fpin=prm->fpscr;
	   if (prm == &Run)
	     {
	      prm->scr_file[0]='\0';
	      prm->fpscr=NULL;
	     }
	   return 0;
	  }
	pr=prm;
	if (pr != &Run || pr->fpscr != NULL)
	  if((pr=prm->next=(struct runit *)malloc(sizeof(struct runit)))== NULL)
	  {
	   err_warn(1,fperr,
		"Error - infinite loop on RUN script file (%s).\n",script_file);
	   script_file[0]='\0';
	   strcpy(script_file,prm->scr_file);
	   fpin=prm->fpscr;
	   if (prm == &Run)
	     {
	      prm->scr_file[0]='\0';
	      prm->fpscr=NULL;
	     }
	   return 0;
	  }
	strcpy(pr->scr_file,script_file);
	pr->fpscr=fpin;
	pr->next=NULL;	
	
/*		Get an attribute name or command			*/

	if ((c = getsttk(str,&tok)) == EOF || c == 0 || tok == EOF)
	  {
	    err_warn(1,fperr,"Error - empty file \n");
	    script_file[0]='\0';
	    fclose(fpin);
	    fpin=NULL;
	    if (pr != &Run) free((char *)pr);
	    else {pr->fpscr=NULL; pr->scr_file[0]='\0';}
	    prm->next=NULL;
	    strcpy(script_file,prm->scr_file);
	    fpin=prm->fpscr;
	    if (prm == &Run)
	      {
	       prm->scr_file[0]='\0';
	       prm->fpscr=NULL;
	      }
	    return 0;
	  };
/*		Process the attribute assignment or command		*/
	do
	  {
/*		Is it an array attribute name?				*/
	   if (strncmp(str,"A_",2) == 0)
	      c=procA_name(str,&tok);
/*		Is it a list name?					*/
	   else if (strncmp(str,"L_",2) == 0)
	      c=procL_name(str,&tok);
/*		Is it a colormap name?					*/
	   else if (strncmp(str,"C_",2) == 0)
	      c=procC_name(str,&tok);
/*		Is it a pattern table name?				*/
	   else if (strncmp(str,"Pat_",4) == 0)
	      c=procPat_name(str,&tok);
/*		Is it a picture element name?				*/
	   else if (strncmp(str,"P_",2) == 0)
	      c=procP_name(str,&tok);
/*		Is it a graphic isoline name?				*/
	   else if (strncmp(str,"Gi_",3) == 0)
	      c=procGi_name(str,&tok);
/*		Is it a graphic outline name?				*/
	   else if (strncmp(str,"Go_",3) == 0)
	      c=procGo_name(str,&tok);
/*		Is it a graphic fill isoline name?			*/
	   else if (strncmp(str,"Gfi_",4) == 0)
	      c=procGfi_name(str,&tok);
/*		Is it a graphic meshfill  name?			*/
	   else if (strncmp(str,"Gfm_",4) == 0)
	      c=procGfm_name(str,&tok);
/*		Is it a graphic outline fill name?			*/
	   else if (strncmp(str,"Gfo_",4) == 0)
	      c=procGfo_name(str,&tok);
/*		Is it a continents name?				*/
	   else if (strncmp(str,"Gcon_",5) == 0)
	      c=procGcon_name(str,&tok);
/*		Is it an boxfill name?					*/
	   else if (strncmp(str,"Gfb_",4) == 0)
	      c=procGfb_name(str,&tok);
/*		Is it a vector name?					*/
	   else if (strncmp(str,"Gv_",3) == 0)
	      c=procGv_name(str,&tok);
/*		Is it an X(y) vs y name?				*/
	   else if (strncmp(str,"GXy_",4) == 0)
	      c=procGXyvy_name(str,&tok);
/*		Is it an Y(x) vs x name?				*/
	   else if (strncmp(str,"GYx_",4) == 0)
	      c=procGYxvx_name(str,&tok);
/*		Is it an X(t) vs Y(t) name?				*/
	   else if (strncmp(str,"GXY_",4) == 0)
	      c=procGXY_name(str,&tok);

/*		Is it a ScatterPlot name?				*/
	   else if (strncmp(str,"GSp_",4) == 0)
	      c=procGSp_name(str,&tok);

/*		Is it a text table name?				*/
	   else if (strncmp(str,"Tt_",3) == 0)
	      c=procTt_name(str,&tok);
/*		Is it a character orientation table name?		*/
	   else if (strncmp(str,"To_",3) == 0)
	      c=procTo_name(str,&tok);
/*		Is it a line table name?				*/
	   else if (strncmp(str,"Tl_",3) == 0)
	      c=procTl_name(str,&tok);
/*		Is it a fill area table name?				*/
	   else if (strncmp(str,"Tf_",3) == 0)
	      c=procTf_name(str,&tok);
/*		Is it a marker table name?				*/
	   else if (strncmp(str,"Tm_",3) == 0)
	      c=procTm_name(str,&tok);
/*		Is it a format table name?				*/
	   else if (strncmp(str,"Th_",3) == 0)
	      c=procTh_name(str,&tok);
/*		Is it a DISPLAY command.				*/
	   else if (strncmp(str,"D_",2) == 0)
		c=procDisp(str,&tok);
/*		Is it a projection name.				*/
	   else if (strncmp(str,"Proj_",5) == 0)
		c=procProj_name(str,&tok);
/*		Is it a Taylordiagram name.				*/
	   else if (strncmp(str,"Gtd_",4) == 0)
	     {
	       while (strncmp(str,")",1) != 0)
		 {
		   fscanf(fpin,"%s",str);		   
		 }
	       continue;
	     }
/*		If none of the above					*/
	   else
	     {
	      if (procCOMM(str,&tok) == 0)
		{
	         err_warn(1,fperr,
			"Error - (%s%c) not found or erroneous.\n",str,tok);
		 script_file[0]='\0';
		 fclose(fpin);
		 fpin=NULL;
		 if (pr != &Run) free((char *)pr);
		 else {pr->fpscr=NULL; pr->scr_file[0]='\0';}
		 prm->next=NULL;
		 strcpy(script_file,prm->scr_file);
		 fpin=prm->fpscr;
		 if (prm == &Run)
		   {
		    prm->scr_file[0]='\0';
		    prm->fpscr=NULL;
		   }
		 return 0;
		}
	     }
	   vcs_canvas_update(0);
	  } while (c != EOF && c != 0 &&
		(c=getsttk(str,&tok)) != EOF && tok != EOF);
	if (c == EOF) c=1;
	
	cur_pos = ftell(fpin);     /* Get the file pointer position */

	script_file[0]='\0';
        fclose(fpin);
	fpin=NULL;
	if (pr != &Run) free((char *)pr);
	else {pr->fpscr=NULL; pr->scr_file[0]='\0';}
	prm->next=NULL;
	strcpy(script_file,prm->scr_file);
	fpin=prm->fpscr;
	if (prm == &Run)
	  {
	   prm->scr_file[0]='\0';
	   prm->fpscr=NULL;
	  }
	return c;
      }
Exemple #22
0
    struct gfm_tab *getGfm(char *str)
      {
       int i;
       struct gfm_tab *p,*p1;
       struct gfm_attr *pa,*pa1;
       struct fill_range *pifr,*pifr1,*pifrn;

/*		Search meshfill table for attributes to be copied.	*/

       for (p1=&Gfm_tab;p1 != NULL;p1=p1->next)
	  if (strcmp(str,p1->name) == 0) break;
       if (p1 == NULL || p1->pGfm_attr == NULL)
	 {
	  err_warn(0,fperr,
	   "Warning - Graphics meshfill (%s) can't be found for get.\n",str);
	  return 0;
	 }
       pa1=p1->pGfm_attr;

/*		Create a new table structure and copy to it.		*/

       if((p=(struct gfm_tab *)malloc(sizeof(struct gfm_tab)))==NULL)
	 {
	  err_warn(1,fperr,
	    "Error - memory for getting Graphics meshfill(%s) not found.\n",
						str);
	  return NULL;
	 }

       strcpy(p->name,p1->name);

/*		Create a new attribute structure and copy to it.	*/

       if((pa=(struct gfm_attr *)malloc(sizeof(struct gfm_attr)))==NULL)
	 {
	  err_warn(1,fperr,
	    "Error - memory for getting Graphics meshfill(%s) not found.\n",
						str);
	  free((char *) p);
	  return NULL;
	 }
       p->pGfm_attr=pa;
       pa->line=NULL;
       strncpy(pa->proj,pa1->proj,VCS_MX_NM_LEN); pa->proj[VCS_MX_NM_LEN-1] = '\0';
       strncpy(pa->xtl1,pa1->xtl1,256); pa->xtl1[255] = '\0';
       strncpy(pa->xtl2,pa1->xtl2,256); pa->xtl2[255] = '\0';
       strncpy(pa->xmt1,pa1->xmt1,256); pa->xmt1[255] = '\0';
       strncpy(pa->xmt2,pa1->xmt2,256); pa->xmt2[255] = '\0';
       strncpy(pa->ytl1,pa1->ytl1,256); pa->ytl1[255] = '\0';
       strncpy(pa->ytl2,pa1->ytl2,256); pa->ytl2[255] = '\0';
       strncpy(pa->ymt1,pa1->ymt1,256); pa->ymt1[255] = '\0';
       strncpy(pa->ymt2,pa1->ymt2,256); pa->ymt2[255] = '\0';
       pa->xwrap=pa1->xwrap;
       pa->ywrap=pa1->ywrap;
       pa->mesh=pa1->mesh;
       for (i=0;i<4;i++) pa->dsp[i]=pa1->dsp[i];
       strncpy(pa->timeunits,pa1->timeunits,256); pa->timeunits[255] = '\0';
       for (i=0;i<4;i++) pa->idsp[i]=pa1->idsp[i];
       pa->calendar=pa1->calendar;
       if (((strcmp(pa1->xat, "linear") != 0) || (strcmp(pa1->xat, "") == 0)) &&            (strcmp(pa->proj, "linear") == 0) ) {
          strncpy(pa->xat,pa1->xat,17); pa->xat[16] = '\0';
       } else {
          strncpy(pa->xat,"linear",17); pa->xat[16] = '\0';
       }
       if (((strcmp(pa1->yat, "linear") != 0) || (strcmp(pa1->yat, "") == 0)) &&            (strcmp(pa->proj, "linear") == 0) ) {
          strncpy(pa->yat,pa1->yat,17); pa->yat[16] = '\0';
       } else {
          strncpy(pa->yat,"linear",17); pa->yat[16] = '\0';
       }
       if ((pa1->missing < 0) || (pa1->missing > 255))
          pa->missing=241;
       else
          pa->missing=pa1->missing;
       if (pa1->legend != NULL) {
          if ((pa->legend=(char *)malloc((strlen(pa1->legend))*sizeof(char)+1))
               == NULL) {
              err_warn(1,fperr,
                       "Error - memory for legend(%s) changes not found. \n",
                        pa1->legend);
              return 0;
	  }
	  strcpy(pa->legend, pa1->legend);
       } else 
          pa->legend=pa1->legend;
       pifr=NULL;
       for (pifr1=pa1->line,pifrn=NULL;pifr1 != NULL;pifr1=pifr1->next)
	 {
	  if((pifrn=
		(struct fill_range *)malloc(sizeof(struct fill_range)))==NULL)
	    {
	     err_warn(1,fperr,
	      "Error - memory for getting Graphics meshfill(%s) not found./n",
					str);
	     killGfm(p);
	     return 0;
	    }
	  if (pa->line == NULL) pa->line=pifrn;
	  else pifr->next=pifrn;
	  pifr=pifrn;

	  pifr->id=pifr1->id;
	  pifr->lev1=pifr1->lev1;
	  pifr->lev2=pifr1->lev2;
	  strncpy(pifr->fill_name,pifr1->fill_name,17); pifr->fill_name[16]='\0';
	  pifr1->fill_name[16]='\0';
	  pifr->next=NULL;
	 }

       return p;
      }
Exemple #23
0
    int copy_Gfo_name(char *str1,char *str2)
      {
       int i,j;
       struct gfo_tab *p,*ptb,*p1;
       struct display_tab *pd;
       struct gfo_attr *pa,*pa1;
       char s[17];

       if (str1==NULL || strprt(str1)==0 || str2==NULL || strprt(str2)==0)
							 return 0;
       if (strcmp(str1,str2) == 0) return 1;

       if (strcmp(str2,Gfo_tab.name) == 0)
	 {
	  err_warn(1,fperr,
	    "Error - Can't copy to the default Fill Outlines (Gfo_%s).\n",
							str2);
	  return 0;
	 }

/*		See if the target Fill Outlines exists.			*/
       for (ptb=p=&Gfo_tab; p != NULL; ptb=p,p=p->next)
	 {
	  if (strcmp(str2,p->name) == 0)
	    {
	     err_warn(1,fperr,
	      "Error - Can't copy to existing Fill Outlines (Gfo_%s).\n",
							str2);
	     return 0;
	    }
	 }

/*		Search Fill outline table for attributes to be copied.	*/

       for (p1=&Gfo_tab;p1 != NULL;p1=p1->next)
	  if (strcmp(str1,p1->name) == 0) break;

       if (p1 == NULL || p1->pGfo_attr == NULL)
	 {
	  err_warn(1,fperr,
	   "Error - Fill Outlines (Gfo_%s) can't be found for copy.\n",str1);
	  return 0;
	 }
       pa1=p1->pGfo_attr;

/*		Create a new attribute structure and copy to it.	*/

       if((pa=(struct gfo_attr *)malloc(sizeof(struct gfo_attr)))==NULL)
	 {
	  err_warn(1,fperr,
	    "Error - memory for Fill Outlines (Gfo_%s) not found for copy.\n",
								str2);
	  return 0;
	 }
       strncpy(pa->proj,pa1->proj,256); pa->proj[255] = '\0';
       strncpy(pa->xtl1,pa1->xtl1,256); pa->xtl1[255] = '\0';
       strncpy(pa->xtl2,pa1->xtl2,256); pa->xtl2[255] = '\0';
       strncpy(pa->xmt1,pa1->xmt1,256); pa->xmt1[255] = '\0';
       strncpy(pa->xmt2,pa1->xmt2,256); pa->xmt2[255] = '\0';
       strncpy(pa->ytl1,pa1->ytl1,256); pa->ytl1[255] = '\0';
       strncpy(pa->ytl2,pa1->ytl2,256); pa->ytl2[255] = '\0';
       strncpy(pa->ymt1,pa1->ymt1,256); pa->ymt1[255] = '\0';
       strncpy(pa->ymt2,pa1->ymt2,256); pa->ymt2[255] = '\0';
       strncpy(pa->timeunits,pa1->timeunits,256); pa->timeunits[255] = '\0';
       for (i=0;i<4;i++) pa->dsp[i]=pa1->dsp[i];
       for (i=0;i<4;i++) pa->idsp[i]=pa1->idsp[i];
       pa->calendar=pa1->calendar;
       strncpy(pa->xat,pa1->xat,17); pa->xat[16] = '\0';
       strncpy(pa->yat,pa1->yat,17); pa->yat[16] = '\0';
       strncpy(pa->f,pa1->f,17); pa->f[16] = '\0';
       pa->n=pa1->n;
       if (pa->n > 0) for (i=0;i<pa->n;i++) pa->out[i]=pa1->out[i];
       
/*		See if the attribute name exists in the fill outline table.
		If not create a table entry.				*/

       if((p=(ptb->next)=(struct gfo_tab *)malloc(sizeof(Gfo_tab))) == NULL)
	 {
	  err_warn(1,fperr,
	     "Error - memory for Fill Outlines (%s) not found for copy.\n",
								str1);
	  free ((char *)pa);
	  return 0;
	 }
       p->pGfo_attr=pa;
       p->next=NULL;
       strcpy(p->name,str2);

       if (!Inactive && fpout != NULL)
		fprintf(fpout,"COPY(Gfo_%s,Gfo_%s)\n",str1,str2);
       return 1;
      }
Exemple #24
0
    int chk_mov_Tt (struct table_text *pt)

      {
       struct table_text *ptb,*ptab;



       if (pt == NULL) return 0;
       	for (ptb=ptab=&Tt_tab;
		ptab!=NULL && cmpnbl(pt->name,ptab->name)!=0;
			ptb=ptab,ptab=ptab->next);

/*		Check if it's trying to overwrite the default.		*/

         if (ptab == &Tt_tab)
	  {
	   err_warn(1,fperr,"Error - can't replace the default (Tt_%s).\n",
				pt->name);
	   free((char *)pt);
	   return 0;
	  }

	if (ptab == NULL)
	  {
	   ptb->next=ptab=pt;
	  }
	else
	  {
/* 	    if (pt->txfont != ptab->txfont ) printf("txfont diff %d,%d\n",pt->txfont, ptab->txfont); */
/* 	    if (pt->txpr != ptab->txpr) printf("txpr diff %d,%d\n",pt->txpr, ptab->txpr); */
/* 	    if (pt->txexp != ptab->txexp ) printf("txexp diff\n"); */
/* 	    if (pt->txsp != ptab->txsp) printf("txsp diff\n");	        */
/* 	    if ( pt->txci != ptab->txci ) printf("txci diff %d,%d\n",pt->txci, ptab->txci); */
/* 	    if ( pt->priority != ptab->priority ) printf("priority diff\n"); */
/* 	    if (ptab->tvp[0] != pt->tvp[0] || ptab->tvp[1] != pt->tvp[1] || */
/* 		ptab->tvp[2] != pt->tvp[2] || ptab->tvp[3] != pt->tvp[3] ) printf("tvp diff\n"); */
/* 	    if ( ptab->twc[0] != pt->twc[0] || ptab->twc[1] != pt->twc[1] || */
/* 		 ptab->twc[2] != pt->twc[2] || ptab->twc[3] != pt->twc[3] ) printf("twc diff\n"); */
/* 	    if (compare_points(ptab->tx, pt->tx )!=1) printf("tx difff\n"); */
/* 	    if (compare_points(ptab->ty, pt->ty )!=1) printf("ty difff\n"); */
/* 	    if (compare_strings(ptab->ts, pt->ts )!=1) printf("ts diff %s %s\n",ptab->ts,pt->ts); */
/* 	    if (strcmp(ptab->proj,pt->proj) != 0) printf("proj diff\n"); */
	       
	   if (pt->txfont != ptab->txfont || pt->txpr != ptab->txpr ||
	       pt->txexp != ptab->txexp || pt->txsp != ptab->txsp ||
	       pt->txci != ptab->txci || pt->txfci != ptab->txfci || 
	       pt->priority != ptab->priority ||
               ptab->tvp[0] != pt->tvp[0] || ptab->tvp[1] != pt->tvp[1] ||
               ptab->tvp[2] != pt->tvp[2] || ptab->tvp[3] != pt->tvp[3] ||
               ptab->twc[0] != pt->twc[0] || ptab->twc[1] != pt->twc[1] ||
               ptab->twc[2] != pt->twc[2] || ptab->twc[3] != pt->twc[3] ||
               compare_points(ptab->tx, pt->tx )!=1 ||
	       compare_points(ptab->ty, pt->ty )!=1 ||
               compare_strings(ptab->ts, pt->ts )!=1 ||
	       (strcmp(ptab->proj,pt->proj) != 0)
	       )
	     {
	       strcpy(ptab->proj,pt->proj);
	       ptab->txfont=pt->txfont;
	       ptab->txpr=pt->txpr;
	       ptab->txexp=pt->txexp;
	       ptab->txsp=pt->txsp;
	       ptab->txci=pt->txci;
	       ptab->txfci=pt->txfci;
	       ptab->priority=pt->priority;
	       ptab->tvp[0]=pt->tvp[0];
	       ptab->tvp[1]=pt->tvp[1];
	       ptab->tvp[2]=pt->tvp[2];
	       ptab->tvp[3]=pt->tvp[3];
	       ptab->twc[0]=pt->twc[0];
	       ptab->twc[1]=pt->twc[1];
	       ptab->twc[2]=pt->twc[2];
	       ptab->twc[3]=pt->twc[3];
	       free_points( &ptab->tx );
	       free_points( &ptab->ty );
	       free_strings( &ptab->ts );
	       if (copy_points( &ptab->tx, pt->tx) == 0) return 0;
	       if (copy_points( &ptab->ty, pt->ty) == 0) return 0;
	       if (copy_strings( &ptab->ts, pt->ts) == 0) return 0;
	       free_points( &pt->tx );
	       free_points( &pt->ty );
	       free_strings( &pt->ts );
	       check_d_text(ptab->name);
	     }
	   free((char *)pt);
	   pt=NULL;
	  }
	if (!Inactive && fpout != NULL) prtTt(fpout,ptab);
	return 1;
      } 
Exemple #25
0
    int chk_mov_Tl (struct table_line *pt)

      {
       float		 deflt=1.0;
       struct table_line *ptb,*ptab;
       extern int	 copy_points();
       extern void	 free_points();

       if (pt == NULL) return 0;
       	for (ptb=ptab=&Tl_tab;
		ptab!=NULL && cmpnbl(pt->name,ptab->name)!=0;
			ptb=ptab,ptab=ptab->next);

/*		Check if it's trying to overwrite the default.		*/

         if (ptab == &Tl_tab)
	  {
	   err_warn(1,fperr,"Error - can't replace the default (Tl_%s).\n",
				pt->name);
	   free((char *)pt);
	   return 0;
	  }

	if (ptab == NULL)
	  {
	   ptb->next=ptab=pt;
	  }
	else
	  {
	   if (pt->ltyp != ptab->ltyp || pt->lwsf != ptab->lwsf ||
	       pt->lci != ptab->lci || pt->priority != ptab->priority ||
               ptab->lvp[0] != pt->lvp[0] || ptab->lvp[1] != pt->lvp[1] ||
               ptab->lvp[2] != pt->lvp[2] || ptab->lvp[3] != pt->lvp[3] ||
               ptab->lwc[0] != pt->lwc[0] || ptab->lwc[1] != pt->lwc[1] ||
               ptab->lwc[2] != pt->lwc[2] || ptab->lwc[3] != pt->lwc[3] ||
               ptab->lx != pt->lx || ptab->ly != pt->ly || (strcmp(ptab->proj,pt->proj) != 0)
               )
	     {
	      strcpy(ptab->proj,pt->proj);
	      copy_int_array( &ptab->ltyp,&pt->ltyp,&ptab->ltyp_size,pt->ltyp_size, 1 );
	      copy_float_array(&ptab->lwsf,&pt->lwsf,&ptab->lwsf_size,pt->lwsf_size,&deflt);
	      copy_int_array( &ptab->lci, &pt->lci, &ptab->lci_size, pt->lci_size, 241 );
              ptab->priority=pt->priority;
	      ptab->lvp[0]=pt->lvp[0];
	      ptab->lvp[1]=pt->lvp[1];
	      ptab->lvp[2]=pt->lvp[2];
	      ptab->lvp[3]=pt->lvp[3];
	      ptab->lwc[0]=pt->lwc[0];
	      ptab->lwc[1]=pt->lwc[1];
	      ptab->lwc[2]=pt->lwc[2];
	      ptab->lwc[3]=pt->lwc[3];
              free_points( &ptab->lx );
              free_points( &ptab->ly );
	      if (copy_points( &ptab->lx, pt->lx) == 0) return 0;
	      if (copy_points( &ptab->ly, pt->ly) == 0) return 0;
              free_points( &pt->lx );
              free_points( &pt->ly );
              if (pt->ltyp != NULL) free((char *) pt->ltyp); pt->ltyp = NULL;
              if (pt->lwsf != NULL) free((char *) pt->lwsf); pt->lwsf = NULL;
              if (pt->lci != NULL) free((char *) pt->lci); pt->lci = NULL;
	      free((char *)pt);
	      pt=NULL;
	      check_d_line(ptab->name);
	     }
	  }
	if (!Inactive && fpout != NULL) prtTl(fpout,ptab);
	return 1;
       } 
Exemple #26
0
void db_free() {
	if(sqlite3_close(g.handle) != SQLITE_OK)
		err_warn(0, "failed to close sqlite db: %s", sqlite3_errmsg(g.handle));
}