Exemplo n.º 1
0
int		get_next_line(int const fd, char **line)
{
	int			ret;
	int			k;
	static char	*tmp[256] = {NULL};
	char		*buf;

	buf = NULL;
	buf = ft_strnew(BUF_SIZE);
	if ((ret = read(fd, buf, BUF_SIZE)) == -1 || line == NULL || buf == NULL)
		return (-1);
	buf[ret] = '\0';
	tmp[fd] = new_join(tmp[fd], buf);
	k = check_linefeed(tmp[fd]);
	(ret == 0 && !tmp[fd][0]) ? ft_strdel(&tmp[fd]) : 0;
	if (ret == 0 && !tmp[fd])
		return (0);
	if (k >= 0 || (k == -1 && ret < BUF_SIZE))
	{
		*line = (k >= 0) ? ft_strsub(tmp[fd], 0, k) : ft_strdup(tmp[fd]);
		if (k == -1)
			ft_strdel(&tmp[fd]);
		else
			tmp[fd] = clear_tmp(tmp[fd], k + 1);
		return (1);
	}
	return (get_next_line(fd, line));
}
Exemplo n.º 2
0
void initialize (int *argc, char **argv[], char ***envp)
{
    char    buf[512], *p;
    char    inifile[MAX_PATH], ifile[MAX_PATH];
    time_t     t1;
    struct tm  tm1;
#ifdef __MINGW32__
    WSADATA wsa;
#endif

    //putenv ("TZ=GMT0");
    //tzset ();

    // first we need to initialize FLY variables
    fly_initialize ();
    fl_opt.appname = "nftp";

    if (fl_opt.has_console)
        fprintf (stderr, "\nNFTP - Version%sof %s, %s"
                 "\nCopyright (C) Sergey Ayukov 1994--2000.\n\n",
                 NFTP_VERSION, __DATE__, __TIME__);

    fly_process_args (argc, argv, envp);

    // checking command-line arguments
    check_args (*argc, *argv);

    // find where our config files are
    determine_paths ((*argv)[0]);

    // delete old temporary files
    clear_tmp ();

    // loading configuration files
    init_config ();

    // initilialize debug subsystem if specified
    if (options.debug)
    {
        sprintf (buf, /*sizeof(buf),*/ "%s/debug", paths.user_libpath);
        mkdir1 (buf, 0700);
        sprintf (buf, /*sizeof(buf),*/ "%s/debug/nftp.dbg.%u", paths.user_libpath, (int)getpid ());
        dbfile = fopen (buf, "w");
        tools_debug = dbfile;
    }

    if (options.log_cc)
    {
        sprintf (buf, /*sizeof(buf),*/ "%s/CC", paths.user_libpath);
        mkdir1 (buf, 0700);
        t1 = time (NULL);
        tm1 = *localtime (&t1);
        sprintf (buf, "CC/%04d-%02d-%02d.%02d:%02d:%02d.log",
                 tm1.tm_year+1900, tm1.tm_mon, tm1.tm_mday,
                 tm1.tm_hour, tm1.tm_min, tm1.tm_sec);
        p = str_sjoin (paths.user_libpath, buf);
        cc_log = fopen (p, "w");
        if (cc_log == NULL) options.log_cc = FALSE;
        free (p);
    }

    // load language-specific things
    nls_init (paths.system_libpath, paths.user_libpath);
    load_menu ();

    // check for correct NFTP.INI version
    strcpy (buf, NFTP_VERSION);
    str_strip2 (buf, " ");
    //if (str_numchars (buf, '.') > 1)  *(strrchr (buf, '.')) = '\0';
    if (strcmp (options.version, buf) != 0)
    {
        // looking for nftp.i file in user dir, then in system dir
        strcpy (ifile, paths.user_libpath);
        str_cats (ifile, "nftp.i");
        if (access (ifile, R_OK) != 0)
        {
            strcpy (ifile, paths.system_libpath);
            str_cats (ifile, "nftp.i");
            if (access (ifile, R_OK) != 0)
                fly_error (MSG(M_INI_CANT_FIND_NFTP_I),
                        paths.user_libpath, paths.system_libpath);
        }
        strcpy (inifile, paths.user_libpath);
        str_cats (inifile, "nftp.ini");
        update_inifile (inifile, ifile);
        GetProfileOptions (inifile);
    }

    config_fly ();

#ifdef __MINGW32__
    WSAStartup (MAKEWORD(1,1), &wsa);
#endif
}
Exemplo n.º 3
0
Arquivo: my_main.c Projeto: stuydw/mdl
void my_main( int polygons ) {

  int i;
  double step;
  double xval, yval, zval;
  struct matrix *transform;
  struct matrix *tmp;
  struct stack *s;
  screen t;
  color g;
  
  s = new_stack();
  tmp = new_matrix(4, 1000);
  clear_screen( t );

  void clear_tmp(){
      for(j = 0; j < tmp->lastcol; j++){
	tmp->m[0][j] = 0;
	tmp->m[1][j] = 0;
	tmp->m[2][j] = 0;
      }
      tmp->lastcol = 0;
  }

  for (i=0;i<lastop;i++) {  
   clear_tmp();
   switch (op[i].opcode) {
  	case COMMENT:
	     break;
	case PUSH:
	     push(s);
	     break;
	case POP:
	     pop(s);
	     break;
	case SAVE:
	     save_extension(t, op[i].op.save.p->name);
             break;
        case  MOVE:
             xval = op[i].op.move.d[0];	
             yval = op[i].op.move.d[1];
             zval = op[i].op.move.d[2];
             transform = make_translate(xval, yval, zval);
             matrix_mult(s->data[s->top], transform);
             s->data[s->top]=transform;
	     break;
	case SCALE:
	     xval = op[i].op.move.d[0];
	     yval = op[i].op.move.d[1];
	     zval = op[i].op.move.d[2];
	     transform = make_scale(xval, yval, zval);
	     matrix_mult(s->data[s->top], transform);
	     s->data[s->top]=transform;
	     break;
	case LINE:
	     xval = op[i].op.line.p0[0];
             yval = op[i].op.line.p0[1];
             zval = op[i].op.line.p0[2];
             x2 = op[i].op.line.p1[0];
             y2 = op[i].op.line.p1[1];
             z2 = op[i].op.line.p1[2];
             add_edge(tmp, xval, yval, zval, x2, y2, z2);
             matrix_mult(s->data[s->top], tmp);
             draw_lines(tmp, t, g);
	     break;
	case BOX:
	     xval = op[i].op.box.d0[0];
             yval = op[i].op.box.d0[1];
             zval = op[i].op.box.d0[2];
             width = op[i].op.box.d1[0];
             height = op[i].op.box.d1[1];
             depth = op[i].op.box.d1[2];
             add_box(tmp, xval, yval, zval, width, height, depth);
             matrix_mult(s->data[s->top], tmp);
             draw_polygons(tmp, t, g);
             break;
	case SPHERE:
 	     xval = op[i].op.sphere.d[0];
             yval = op[i].op.sphere.d[1];
             zval = op[i].op.sphere.d[2];
             radius = op[i].op.sphere.r;
	     add_sphere(tmp, xval, yval, zval, radius, step);
      	     matrix_mult(s->data[s->top], tmp);
             draw_polygons(tmp, t, g);
             break;
	case TORUS:
	     xval = op[i].op.torus.d[0];
             yval = op[i].op.torus.d[1];
             zval = op[i].op.torus.d[2];
             r1 = op[i].op.torus.r0;
             r2 = op[i].op.torus.r1;
             add_torus(tmp, xval, yval, zval, r1, r2, step);
             matrix_mult(s->data[s->top], tmp);
             draw_polygons(tmp, t, g);
             break;
	case DISPLAY:
             display(t);
             break;
    }
  }
}
Exemplo n.º 4
0
void vm_render_dorender(struct rpg_render *in, struct obj *omain)
{
	struct var *cam_pos, *layer_opacity, *opacity, *f_rgb, *f_o, *tmp;
	struct r_sprite *rtmp;
	struct r_tmap *ttmp;
	int i, j, camx, camy;
	
	
	
	cam_pos = get_var_from_cstr(omain->vars, "cam_pos");
	
	var_force_coord(cam_pos);
	
	camx = cam_pos->dat_list->dat_int;
	camy = cam_pos->dat_list->list_next->dat_int;
	
	
	for (i=0;i<8;i++)
	{
		
		layer_opacity = get_var_from_cstr(omain->vars, "tmap_layer_opacity");
		opacity = lst_get_idx(layer_opacity, i);
		
		/* render tilemap layer if visible */
		if (opacity->dat_int > 0)
		{
			clear_tmp(in->win);
			
			/*prefill*/
			
			/*draw tilemaps to tmp*/
			ttmp = in->tmaps[i];
			while (ttmp != 0)
			{
				render_tmap(ttmp, in->win->t_surf, camx, camy);
				ttmp = ttmp->next;
			}
			
			/* blit t_surf to m_surf */
			blit_surf(in->win->t_surf, in->win->m_surf, 0,0);
		}
		
		layer_opacity = get_var_from_cstr(omain->vars, "sprt_layer_opacity");
		opacity = lst_get_idx(layer_opacity, i);
		/* render sprite layer if visible */
		if (opacity->dat_int > 0)
		{
			clear_tmp(in->win);
			
			/*prefill*/
			/* draw sprites of current layer to tmp*/
			rtmp = in->sprites[i];
			while (rtmp != 0)
			{
				render_sprite(rtmp, in->win->t_surf, camx, camy);
				rtmp = rtmp->next;
			}
			blit_surf(in->win->t_surf, in->win->m_surf,0,0);
			
		}
		
	}
	
	/* render fade overlay */
	f_rgb = get_var_from_cstr(omain->vars, "fad_color");
	f_o = get_var_from_cstr(omain->vars, "fad_opacity");
		
	fill_surf_rgba(
		in->win->t_surf,
		lst_get_idx(f_rgb, 0)->dat_int,
		lst_get_idx(f_rgb, 1)->dat_int,
		lst_get_idx(f_rgb, 2)->dat_int,
		f_o->dat_int
		);
		
	blit_surf(in->win->t_surf, in->win->m_surf,0,0);
}
Exemplo n.º 5
0
int main(int argc,char** argv)
{   

/*===================================
0 - First start.
1 - Model menu.
2 - Enter process menu.
3 - Feynman diagrams menu; squaring.
4 - Squared diagram menu; symbolic calculation.                        
5 - Write results; new process.
10 -Restart symbolic calculations
==========================================================*/

/* 0-Start; 1-Restart; 2-Heap Error,3-Edit Model,4-UserBreak */

  void *pscr1=NULL,*pscr2=NULL,*pscr3=NULL,*pscr4=NULL,*pscr5=NULL;
  int   k1=1,k2=1,k3=1,k4=1,k5=1;

  int n;
  int pid=0;
  char LOCKtxt[]="Directory 'results/' contains the .lock file created by n_calchep.\n"
                 "To continue you may a)Close the n_calchep session, or b)Rename 'results/',\n";
  blind=0;
  strcpy(pathtocomphep,argv[0]);
  for(n=strlen(pathtocomphep)-1; n && pathtocomphep[n]!=f_slash; n--);
  pathtocomphep[n-3]=0;                                         
     
   for ( n=1;n<argc;n++) 
   { if (strcmp(argv[n],"-blind")==0 && n<argc-1 )
     {  blind=1;
        inkeyString=argv[++n];
     }
     if (strcmp(argv[n],"+blind")==0 )  blind=2;                                     
   }    

   if(!writeLockFile(".lock")) 
   { fprintf(stderr,"locked by other s_calchep. See .lock file\n");
      exit(100);
   }
   strcpy(pathtouser,"");  
   sprintf(pathtohelp,"%shelp%c",pathtocomphep,f_slash);
   outputDir="results/";        
   { char * icon=(char *) malloc(strlen(pathtocomphep)+10);
     int err;
     sprintf(icon,"%sicon",pathtocomphep);
     err=start1("CalcHEP/symb",icon,"calchep.ini",&xw_error);
     if(err && blind==0)
     { printf("Error:You have launched interactive session for version compiled  without X11 library.\n");
       printf("Options: a) Use blind session; b) Recompile CalcHEP with X11\n");
       exit(66);
     }      
     free(icon);
   }
   fillModelMenu();
   
   f3_key[0]=f3_key_prog;   f3_mess[0]="Model"; 
   f3_key[1]=f4_key_prog;   f3_mess[1]="Diagrams"; 
   f3_key[2]=f5_key_prog;   f3_mess[2]="Switches";
   f3_key[3]=f6_key_prog;   f3_mess[3]="Results"; 
                            f3_mess[4]="Del"; 
                            f3_mess[5]="UnDel";
   f3_key[6]=f9_key_prog;   f3_mess[6]="Ref";    
   f3_key[7]=f10_key_prog;  f3_mess[7]="Quit";

   restoreent(&menulevel);

   if(!blind && menulevel<2) cheplabel(); 

   switch (menulevel)
   {
      case 10: 
      case 6:
      case 5: 
      case 4:
      case 3: readModelFiles("./models",n_model); 
              modelinfo();
              loadModel(0,forceUG);
              processinfo();
              diagramsinfo();
      case 2: k1=n_model;

      case 1: break;
   }

   switch (menulevel)
   {
      case 2:  menuhelp();
               goto label_20;
      case 3:  goto label_31;
      case 4:  goto label_40;
      case 5:  goto label_50;
      case 6:  
      case 10: goto restart2;
   }
        
label_10:   /*   Menu2(ModelMenu): */
   f3_key[0]=NULL; /*models*/ 
   f3_key[1]=NULL; /*diagrams*/
   menulevel = 1;
   forceUG=0;
   menuhelp();
   for(;;)
   { 
      showheap();
      k1=n_model;
      menu1(56,4,"",modelmenu,"s_1",&pscr1,&k1);
      n_model=k1;
      if(n_model == 0)
      {
	if( mess_y_n(56,4,"Quit session")) {  saveent(menulevel); goto exi; }         
      }
      else  if(n_model == maxmodel+1)
      {
         clrbox(1,4,55,18);
         makenewmodel();
         menuhelp();
      }
      else if (n_model > 0)
      { 
	put_text(&pscr1);
	goto label_20;
      }
   }

label_20:   /*  Menu3:Enter Process  */
   f3_key[0]=NULL; 
   f3_key[1]=NULL; 

   menulevel = 2;
   saveent(menulevel);
   readModelFiles("./models",n_model);
   modelinfo();
   k2 = 1;
   do
   {  char strmen[]="\026"
        " Enter Process        "
        " Force Unit.Gauge OFF "
        " Edit model           "
        " Delete model         ";

      if(forceUG)improveStr(strmen,"OFF","ON");
      menu1(56,4,"",strmen,"s_2_*",&pscr2,&k2);
      switch (k2)
      {
         case 0:  goto_xy(1,1); clr_eol(); goto label_10;
         case 2:  forceUG=!forceUG;   modelinfo(); break;
	 case 3:  editModel(1); break;
         case 4: 
	    if ( deletemodel(n_model) )
            {
               goto_xy(1,1);
               clr_eol();
               n_model=1;
               fillModelMenu();
               goto label_10;
            }
            else   readModelFiles("./models",n_model);
      }
   }  while (k2 != 1);

   loadModel(0,forceUG);
label_21:

   f3_key[0]=NULL; 
   f3_key[1]=NULL; 

   menulevel=2;
   errorcode=enter();   /*  Enter a process  */
   newCodes=0;
   showheap();
   if (errorcode)   /*  'Esc' pressed  */ { menuhelp(); goto label_20;}
   errorcode=construct();          /*  unSquared diagrams  */
   if (errorcode) 
   {  if(blind)
      {  printf("Processes of this type are absent\n"); sortie(111); } 
      else 
      { messanykey(5,22,"Processes of this type are absent");  
        clrbox(1,19,80,24); 
        goto label_21;
      }
   }
   else if(!blind)
   { int dirStat=checkDir("results"); 
     if(dirStat!=0)
     {  messanykey( 10,10,"There are files in directory 'results/'.\n"  
                          "To continue you has to clean or rename this directory.");
        viewresults();
        if(checkDir("results")!=0)  goto label_21;                   
     }
     clr_scr(FGmain,BGmain);
     modelinfo();
     processinfo();
     diagramsinfo();
     goto label_31;	
   }
   
label_30: /*  Menu4: Squaring,...*/
   clr_scr(FGmain,BGmain);
   modelinfo();
   processinfo();
   diagramsinfo();
label_31: 

   f3_key[0]=f3_key_prog; 
   f3_key[1]=NULL; 

   menulevel=3;  
   k3 = 1;
   do
   {
      menu1(56,4,"","\026"
         " View diagrams        "
/*         " Amplitude calculation" */
         " Squaring technique   "
         " Write down processes ","s_squa_*",&pscr3,&k3);
      switch (k3)
      {
         case 0: clrbox(1,2,55,11); menuhelp(); goto label_20;
         case 1: viewfeyndiag(1);   break;
         case 3: { FILE*f=fopen("results/list_prc.txt","w");
                   int k,ndel,ncalc,nrest;
                   char process[100];
                   long recpos; 
                   menup=fopen(MENUP_NAME,"r");
                   for(k=1;;k++) 
                   { int err=rd_menu(1,k,process,&ndel,&ncalc,&nrest,&recpos);
                     if(!err) break;
                     trim(process);
                     fprintf(f,"%s\n",process);
                   } 
                   fclose(f);
                   fclose(menup);
                    messanykey(20,14,"See file 'results/list_prc.txt'");
 
                 } break; 

/*       case 2: messanykey(10,10,"Not implemented yet"); Amplitudes(); */
      }
   }  while (k3 != 2);      

   if (!squaring()) goto label_30;  /*  process is absent  */

   clear_tmp();

   saveent(menulevel);
   restoreent(&menulevel);  

label_40:   /*  Menu5: View squared diagrams.....   */

   f3_key[0]=f3_key_prog; 
   f3_key[1]=f4_key_prog; 

   menulevel=4;
   clr_scr(FGmain,BGmain);
   modelinfo();
   processinfo();
   diagramsinfo();
   sq_diagramsinfo(); /*   ????????   */

   k4=1;
   saveent(menulevel);
   pscr4=NULL;
   for(;;)   
   {  int res;
      menu1(56,4,"","\026"
         " View squared diagrams"
         " Symbolic calculations"
         " Make&Launch n_calchep"        
         " Make n_calchep       "
         " REDUCE program       "
         ,"s_calc_*",&pscr4,&k4);

      res=checkDir("results");
      if(res==1)
      {
        int  n_calchep_id=setLockFile("results/.lock");
        if(n_calchep_id) unLockFile(n_calchep_id); else res=2;                          
      }
      switch (k4)
      {  case 0:
            if (mess_y_n(50,3,"Return to previous menu?"))goto label_30;
         break;

         case 1:
            viewsqdiagr();  break;

         case 2:     /*  Compute all diagrams   */
restart2:
            f3_key[0]=f3_key_prog; 
            f3_key[1]=f4_key_prog; 

            menulevel=4;
            calcallproc();
            sq_diagramsinfo();

            if(!continuetest()) break; 
            showheap();  
            put_text(&pscr4);
         break;
         case 3:
            { static char keystr[12]="]{{[{";
              if(res==2) messanykey(3,10,LOCKtxt); else inkeyString=keystr;
            }
            break;
         case 4:
            if(res==2) messanykey(3,10,LOCKtxt); else
            { char command[100];
              FILE *f=fopen("results/EXTLIB","w");
              fprintf(f,"EXTLIB=\"%s\"\nexport EXTLIB\n",EXTLIB);
              fclose(f); 
              saveent(menulevel);
{ char command[100];
  sprintf(command,"cd results; $CALCHEP/bin/make_VandP  ../models  %d",n_model);
  system(command);
}                 
              finish();
              sortie(22);
            }
         case 5:  mk_reduceprograms();  break;
      }
      if(k4==2 && continuetest()) { put_text(&pscr4); break; }
   }

label_50:
   k5=1;
   pscr5=NULL;
   menulevel=5;
   saveent(menulevel);
   
   for(;;)  
   {  int n_calchep_id;   
      menu1(56,4,"","\026"
         " C code               "
         "     C-compiler       "
         "     Edit Linker      "
         " REDUCE code          "
         " MATHEMATICA code     "
         " FORM code            "
         " Enter new process    " ,"s_out_*",&pscr5,&k5);
         
      if((k5==1||k5==2)&&pid) 
      { int epid=waitpid(pid,NULL,WNOHANG);
        if(epid) pid=0; else
        { 
          messanykey(3,10,"This option is frozen while n_calchep runs or is compiled");
          continue;
        }
      }  

      switch (k5)
      {  case 0: goto label_40;  break;
         case 1:
           c_prog(); newCodes=0; saveent(menulevel);
           break;
         case 2:
           if(newCodes) { c_prog(); newCodes=0; saveent(menulevel);} 
           pid=fork();
           if(pid==0)
           { 
             char * command;
             n_calchep_id=setLockFile("results/.lock"); 
             if(n_calchep_id)
             {  
               command=(char*)malloc(strlen(pathtocomphep)+strlen(EXTLIB)+100);
               sprintf(command,"EXTLIB=\"%s\"\n"
                               "export EXTLIB\n"
                               "cd results\n"
                               "xterm -e %s/make__n_calchep %d",
                               EXTLIB,pathtocomphep,n_model);                                 
               system(command);
               sprintf(command,"cd results; ./n_calchep"); 
               unLockFile(n_calchep_id);
               system(command); 
               free(command);
             }
             exit(0);
           }
           break;
         case 3: if(edittable(1,1,&modelTab[4],1," ",0))
                 {  char fName[STRSIZ];
                    readEXTLIB();
                    sprintf(fName,"%smodels%c%s%d.mdl",pathtouser,f_slash,mdFls[4],n_model);
                    writetable( &modelTab[4],fName); 
                 }
                 break;
         case 4: makeReduceOutput(); break;
         case 5: makeMathOutput();   break; 
	 case 6: makeFormOutput();   break;
   
         case 7:
            put_text(&pscr5);
            clrbox(1,2,55,11);
            menuhelp();
            goto label_20;
      }
   }

exi:
   finish();
   sortie(0);
   return 0;
}
Exemplo n.º 6
0
int main(int argc,char** argv)
{   

/*===================================
0 - First start.
1 - Model menu.
2 - Enter process menu.
3 - Feynman diagrams menu; squaring.
4 - Squared diagram menu; symbolic calculation.                        
5 - Write results; new process.
10 -Restart symbolic calculations
==========================================================*/

/* 0-Start; 1-Restart; 2-Heap Error,3-Edit Model,4-UserBreak */

  void *pscr1=NULL,*pscr2=NULL,*pscr3=NULL,*pscr4=NULL,*pscr5=NULL;
  int   k1=1,k2=1,k3=1,k4=1,k5=1;

  int n;
  int pid=0;
  char LOCKtxt[]="Directory 'results/' contains the .lock file created by n_calchep.\n"
                 "To continue you may a)Close the n_calchep session, or b)Rename 'results/',\n";


  blind=0;
  strcpy(pathtocalchep,argv[0]);
  for(n=strlen(pathtocalchep)-1; n && pathtocalchep[n]!=f_slash; n--);
  pathtocalchep[n-3]=0;                                         
     
   for ( n=1;n<argc;n++) 
   { if (strcmp(argv[n],"-blind")==0 && n<argc-1 )
     {  blind=1;
        inkeyString=argv[++n];
     }
     if (strcmp(argv[n],"+blind")==0 )  blind=2;                                     
     if (strcmp(argv[n],"--version")==0 ) { printf("%s\n", VERSION_); exit(0);}
   }    

   if(!writeLockFile(".lock")) 
   { fprintf(stderr,"locked by other s_calchep. See .lock file\n");
      exit(100);
   }
   strcpy(pathtouser,"");  
   sprintf(pathtohelp,"%shelp%c",pathtocalchep,f_slash);
   outputDir="results/";        
   { char * icon=(char *) malloc(strlen(pathtocalchep)+20);
     char  title[30];
     int err;
     sprintf(icon,"%s/include/icon",pathtocalchep);
     sprintf(title,"CalcHEP_%s/symb", VERSION);
     err=start1(title,icon,"calchep.ini",&xw_error);
     if(err && blind==0)
     { printf("Error:You have launched interactive session for version compiled  without X11 library.\n");
       printf(" Presumably X11 development package is not installed in your computer.\n");
       printf(" In this case directory /usr/include/X11/ is empty.\n");       
       printf("Options: a) Use blind session; b) Update Linux and recompile CalcHEP \n");
       printf("Name of needed package\n");
       printf("     libX11-devel      Fedora/Scientific Linux/CYGWIN/Darwin(MAC)\n");
       printf("     libX11-dev        Ubuntu/Debian\n");
       printf("     xorg-x11-devel    SUSE\n");

       exit(66);
     }      
     free(icon);
   }
   fillModelMenu();
   
   f3_key[0]=f3_key_prog;   f3_mess[0]="Model"; 
   f3_key[1]=f4_key_prog;   f3_mess[1]="Diagrams"; 
   f3_key[2]=f5_key_prog;   f3_mess[2]="Switches";
   f3_key[3]=f6_key_prog;   f3_mess[3]="Results"; 
                            f3_mess[4]="Del"; 
                            f3_mess[5]="UnDel";
   f3_key[6]=f9_key_prog;   f3_mess[6]="Ref";    
   f3_key[7]=f10_key_prog;  f3_mess[7]="Quit";

   restoreent(&menulevel);

   if(!blind && menulevel<2) cheplabel(); 

   switch (menulevel)
   {
      case 10: 
      case 6:
      case 5: 
      case 4:
      case 3: readModelFiles("./models",n_model); 
              modelinfo();
              loadModel(0,forceUG);
              processinfo();
              diagramsinfo();
              k1=n_model;
              break;
      case 2: k1=n_model;
              readModelFiles("./models",n_model);
              break; 
   }

   switch (menulevel)
   {
      case 2:  menuhelp();
               goto label_20;
      case 3:  goto label_31;
      case 4:  goto label_40;
      case 5:  goto label_50;
      case 6:  
      case 10: goto restart2;
   }
        
label_10:   /*   Menu2(ModelMenu): */
   f3_key[0]=NULL; /*models*/ 
   f3_key[1]=NULL; /*diagrams*/
   menulevel = 1;
   forceUG=0;
   menuhelp();
   for(;;)
   { 
      showheap();
      k1=n_model;
      menu1(56,4,"",modelmenu,"s_1",&pscr1,&k1);
      if(k1 == 0)
      {  
	if( mess_y_n(56,4,"Quit session")) {n_model=0;   saveent(menulevel); goto exi; }         
      }
      else  if(k1 == maxmodel+1)
      {
         clrbox(1,4,55,18);
         makenewmodel();
         menuhelp();
      }
      else if (k1 > 0)
      { int err=0;
        put_text(&pscr1);
        if(k1!=n_model || ldModelStatus==0) { err=readModelFiles("./models",k1);}
        n_model=k1;
        if(err){ if(blind) sortie(133); else  goto label_10;} else goto label_20;
      }
   }

label_20:   /*  Menu3:Enter Process  */
   f3_key[0]=NULL; 
   f3_key[1]=NULL; 

   menulevel = 2;
   saveent(menulevel);
   
   modelinfo();
   k2 = 1;
   
   do
   {  char strmen[]="\026"
        " Enter Process        "
        " Force Unit.Gauge= OFF"
        " Edit model           "
        " Numerical Evaluation "
        "======================"
        " Delete model         ";

      if(forceUG)improveStr(strmen,"OFF","ON");
      menu1(56,4,"",strmen,"s_2_*",&pscr2,&k2);
      switch (k2)
      {
         case 0:  goto_xy(1,1); clr_eol(); goto label_10;
         case 2:  forceUG=!forceUG;   modelinfo(); break;
	 case 3:  editModel(1); break;
	 case 4:  numcheck();   
	 case 5:  break;
         case 6: 
	    if(deletemodel(n_model))
            {
               goto_xy(1,1);
               clr_eol();
               n_model=1;
               ldModelStatus=0;
               fillModelMenu();
               goto label_10;
            }
      }
   }  while (k2 != 1);

   if(!loadModel(0,forceUG)) goto  label_20;
   
label_21:

   f3_key[0]=NULL; 
   f3_key[1]=NULL; 
   
   menulevel=2;
   checkAuxDir(n_model);
   errorcode=enter();   /*  Enter a process  */
   newCodes=0;
   showheap();
   if (errorcode)   /*  'Esc' pressed  */ { menuhelp(); goto label_20;}
   errorcode=construct();          /*  unSquared diagrams  */
   if (errorcode) 
   {  if(blind)
      {  printf("Processes of this type are absent\n"); sortie(111); } 
      else 
      { messanykey(5,22,"Processes of this type are absent");  
        clrbox(1,19,80,24); 
        goto label_21;
      }
   }
   else if(!blind)
   { int dirStat=checkDir("results"); 
     if(dirStat!=0)
     {  messanykey( 10,10,"There are files in directory 'results/'.\n"  
                          "To continue you has to clean or rename this directory.");
        viewresults();
        if(checkDir("results")!=0)  goto label_21;                   
     }
     clr_scr(FGmain,BGmain);
     modelinfo();
     processinfo();
     diagramsinfo();
     goto label_31;	
   }
   
label_30: /*  Menu4: Squaring,...*/
   clr_scr(FGmain,BGmain);
   modelinfo();
   processinfo();
   diagramsinfo();
label_31: 

   f3_key[0]=f3_key_prog; 
   f3_key[1]=NULL; 

   menulevel=3;  
   k3 = 1;
   do
   {
      menu1(56,4,"","\026"
         " View diagrams        "
/*         " Amplitude calculation" */
         " Square diagrams      "
         " Write down processes ","s_squa_*",&pscr3,&k3);
      switch (k3)
      {
         case 0: clrbox(1,2,55,11); menuhelp(); goto label_20;
         case 1: viewfeyndiag(1);   break;
         case 3: { FILE*f=fopen("results/list_prc.txt","w");
                   int k,ndel,ncalc,nrest;
                   char process[100];
                   long recpos; 
                   menup=fopen(MENUP_NAME,"r");
                   for(k=1;;k++) 
                   { int err=rd_menu(1,k,process,&ndel,&ncalc,&nrest,&recpos);
                     if(!err) break;
                     trim(process);
                     fprintf(f,"%s\n",process);
                   } 
                   fclose(f);
                   fclose(menup);
                    messanykey(20,14,"See file 'results/list_prc.txt'");
 
                 } break; 

/*       case 2: messanykey(10,10,"Not implemented yet"); Amplitudes(); */
      }
   }  while (k3 != 2);      

   if (!squaring()) goto label_30;  /*  process is absent  */

   clear_tmp();

   saveent(menulevel);
   restoreent(&menulevel);  

label_40:   /*  Menu5: View squared diagrams.....   */

   f3_key[0]=f3_key_prog; 
   f3_key[1]=f4_key_prog; 

   menulevel=4;
   clr_scr(FGmain,BGmain);
   modelinfo();
   processinfo();
   diagramsinfo();
   sq_diagramsinfo(); /*   ????????   */

   k4=1;
   saveent(menulevel);
   pscr4=NULL;
   for(;;)   
   {  int res;
      menu1(56,4,"","\026"
         " View squared diagrams"
         " Symbolic calculations"
         " Make&Launch n_calchep"        
         " Make n_calchep       "
         " REDUCE program       "
         ,"s_calc_*",&pscr4,&k4);

      res=checkDir("results");
      if(res==1)
      {
        int  n_calchep_id=setLockFile("results/.lock");
        if(n_calchep_id) unLockFile(n_calchep_id); else res=2;                          
      }
      switch (k4)
      {  case 0:
            if (mess_y_n(50,3,"Return to previous menu?"))goto label_30;
         break;

         case 1:
            viewsqdiagr();  break;

         case 2:     /*  Compute all diagrams   */
restart2:
            f3_key[0]=f3_key_prog; 
            f3_key[1]=f4_key_prog; 

            menulevel=4;
                        
            if(!nPROCSS ) calcallproc(); else 
            { int *pids=malloc(sizeof(int)*nPROCSS);
              int *pipes=malloc(2*sizeof(int)*nPROCSS);
              int **qd=malloc(sizeof(int*)*nPROCSS);
              int totD=sqDiagList(qd, nPROCSS);
              int totC,nProc;
              int k;
              
              fflush(NULL);
              for(k=0;k<nPROCSS;k++) 
              { int* kpipe=pipes+2*k;
                pipe(kpipe);
                pids[k]=fork();
                if(pids[k]==0)
                { 
                  close(kpipe[0]);
                  calcWithFork(k,qd[k],kpipe[1]);
                  exit(0);
                }
              }
              for(k=0;k<nPROCSS;k++) close(pipes[2*k+1]);
              infoLine(0.);
              for(nProc=nPROCSS,totC=0;nProc;)
              { int one;
                int err;
                nProc=0;
                for(k=0;k<nPROCSS;k++) if(pids[k])
                { if(waitpid(pids[k],NULL,WNOHANG)==0)
                  {  nProc++; 
                     if(read(pipes[2*k],&one,sizeof(int)))totC+=one;
                  } else 
                  { for(;read(pipes[2*k],&one,sizeof(int))>0;) totC+=one;
                     pids[k]=0;
                  }
                }  
                if(infoLine((double)totC/(double)totD)) for(k=0;k<nPROCSS;k++) if(pids[k]) kill(pids[k],SIGUSR1);   
              }  
              infoLine(2);
              for(k=0;k<nPROCSS;k++)
              { char ctlgName[100];
                char command[200];
                sprintf(ctlgName,"%s_%d",CATALOG_NAME,k);
                if(access(ctlgName,R_OK)==0)
                { sprintf(command," cat %s >> %s", ctlgName,CATALOG_NAME);
                  system(command);
                  unlink(ctlgName);   
                }
              }
              if(totC)  newCodes=1;  
              updateMenuQ();
              
              for(k=0;k<nPROCSS;k++) close(pipes[2*k]);
              free(pids);   
              free(pipes);
              for(k=0;k<nPROCSS;k++) free(qd[k]);
              free(qd);   
            }
            
            sq_diagramsinfo();

            if(!continuetest()) break; 
            showheap();  
            put_text(&pscr4);
         break;
         case 3:
            { static char keystr[12]="]{{[{";
              if(res==2) messanykey(3,10,LOCKtxt); else inkeyString=keystr;
            }
            break;
         case 4:
            if(res==2) messanykey(3,10,LOCKtxt); else
            { char command[100];
              saveent(menulevel);
              chdir("results");
              makeVandP(0,"../models",n_model,2,pathtocalchep);
              finish();
              sortie(22);
            }
         case 5:  mk_reduceprograms();  break;
      }
      if(k4==2 && continuetest()) { put_text(&pscr4); break; }
   }

label_50:
   k5=1;
   pscr5=NULL;
   menulevel=5;
   saveent(menulevel);
   sq_diagramsinfo();
      
   for(;;)  
   {  int n_calchep_id;   
      menu1(56,4,"","\026"
         " C code               "
         "     C-compiler       "
         "     Edit Linker      "
         " REDUCE code          "
         " MATHEMATICA code     "
         " FORM code            "
         " Enter new process    " ,"s_out_*",&pscr5,&k5);
          
      if((k5==1||k5==2)&&pid) 
      { int epid=waitpid(pid,NULL,WNOHANG);
        if(epid) pid=0; else
        { 
          messanykey(3,10,"This option is frozen while n_calchep runs or is compiled");
          continue;
        }
      }  

      switch (k5)
      {  case 0: goto label_40;  break;
         case 1:
           c_prog(); newCodes=0; saveent(menulevel);
           break;
         case 2:
           if(newCodes) { c_prog(); newCodes=0; saveent(menulevel);}
          n_calchep_id=setLockFile("results/.lock"); 
           if(n_calchep_id)
           {
             if(nPROCSS)
             { chdir("results"); 
                makeVandP(0,"../models",n_model,2,pathtocalchep);
               pCompile();
               if(access("./n_calchep",X_OK)==0)
               { 
                  fflush(NULL); 
                  pid=fork();   
                  if(pid==0) 
                  {
                    system("./n_calchep");
                    exit(0);
                  }    
               } else messanykey(15,15,"n_calchep is not generated");
               chdir("../");
             } else                       
             { fflush(NULL); 
               pid=fork();
               if(pid==0)
               {  if(chdir("results")==0)
                  {   char*command=malloc(100+strlen(pathtocalchep));
                      makeVandP(0,"../models",n_model,2,pathtocalchep); 
                      sprintf(command,"xterm -e %s/sbin/make__n_calchep %d", pathtocalchep,n_model);                                 
                      system(command);
                      free(command);
                      system("./n_calchep");                     
                   }
                   exit(0);    
               }
             }
             unLockFile(n_calchep_id); 
           } 
           break;
         case 3: if(edittable(1,1,&modelTab[4],1," ",0))
                 {  char fName[STRSIZ];
                    sprintf(fName,"%smodels%c%s%d.mdl",pathtouser,f_slash,mdFls[4],n_model);
                    writetable( &modelTab[4],fName); 
                 }
                 break;
         case 4: makeReduceOutput(); break;
         case 5: makeMathOutput();   break; 
	 case 6: makeFormOutput();   break;
   
         case 7:
            put_text(&pscr5);
            clrbox(1,2,55,11);
            menuhelp();
            goto label_20;
      }
   }

exi:
   finish();
   sortie(0);
   return 0;
}
Exemplo n.º 7
0
void initialize (int *argc, char **argv[], char ***envp)
{
    char    buf[512];
    char    inifile[MAX_PATH], ifile[MAX_PATH];
#ifdef __MINGW32__    
    WSADATA wsa;
#endif

    //putenv ("TZ=GMT0");
    //tzset ();
    
    // first we need to initialize FLY variables
    fly_initialize ();
    fl_opt.appname = "nftp";
    
    if (fl_opt.has_console)
        fprintf (stderr, "\nNFTP - Version%sof %s, %s"
                 "\nCopyright (C) Sergey Ayukov 1994-2003.\n\n",
                 NFTP_VERSION, __DATE__, __TIME__);

    fly_process_args (argc, argv, envp);
    
    // checking command-line arguments
    check_args (*argc, *argv);
    
    // find where our config files are
    determine_paths ((*argv)[0]);

    // delete old temporary files
    clear_tmp ();
    
    // loading configuration files
    init_config ();

    // initilialize debug subsystem if specified
    if (options.debug)
    {
        snprintf1 (buf, sizeof(buf), "%s/debug", paths.user_libpath);
#ifdef __WIN32__        
        mkdir (buf);
#else
        mkdir (buf, 0700);
#endif
        snprintf1 (buf, sizeof(buf), "%s/debug/nftp.dbg.%u", paths.user_libpath, (int)getpid ());
        dbfile = fopen (buf, "w");
        tools_debug = dbfile;
    }

    // load language-specific things
    /*nls_init (paths.system_libpath, paths.user_libpath);*/
    load_menu ();

    // check for correct NFTP.INI version
    strcpy (buf, NFTP_VERSION);
    str_strip2 (buf, " ");
    //if (str_numchars (buf, '.') > 1)  *(strrchr (buf, '.')) = '\0';
    if (strcmp (options.version, buf) != 0)
    {
        // looking for nftp.i file in user dir, then in system dir
        strcpy (ifile, paths.user_libpath);
        str_cats (ifile, "nftp.i");
        if (access (ifile, R_OK) != 0)
        {
            strcpy (ifile, paths.system_libpath);
            str_cats (ifile, "nftp.i");
            if (access (ifile, R_OK) != 0)
                fly_error (M("Cannot find nftp.i to update nftp.ini\n"
                             "neither in '%s' nor in '%s'!"),
                           paths.user_libpath, paths.system_libpath);
        }
        strcpy (inifile, paths.user_libpath);
        str_cats (inifile, "nftp.ini");
        // ask user and update ini file
        //if (fl_opt.has_console) // otherwise it's too annoying
        //{
        //    fprintf (stderr, M("Your current config file, %s, has version %s.\n"
        //         "NFTP executable version number is %s."),
        //         inifile, options.version, buf);
        //    fprintf (stderr, M(
        //            "Going to update   '%s'\n"
        //            "from              '%s'.\n"
        //            "Proceed? [Ynq]", inifile, ifile);
        //    fgets (buf, sizeof(buf), stdin);
        //    switch (buf[0])
        //    {
        //    case 'Q': case 'q': exit (0);
        //    case 'N': case 'n': break;
        //    case 'Y': case 'y': default:
        //        update_inifile (inifile, ifile);
        //    }
        //}
        //else
        //{
            update_inifile (inifile, ifile);
        //}
        GetProfileOptions (inifile);
    }
    
    config_fly ();

#ifdef __MINGW32__    
    WSAStartup (MAKEWORD(1,1), &wsa);
#endif
}