Beispiel #1
0
/*
 * Write a line to the output or not, according to command line options.
 * If writing fails, closeout() will print the error and exit.
 */
static void
flushline(bool keep)
{
	if (symlist)
		return;
	if (keep ^ complement) {
		bool blankline = tline[strspn(tline, " \t\r\n")] == '\0';
		if (blankline && compblank && blankcount != blankmax) {
			delcount += 1;
			blankcount += 1;
		} else {
			if (lnnum && delcount > 0)
				hashline();
			if (fputs(tline, output) == EOF)
				closeout();
			delcount = 0;
			blankmax = blankcount = blankline ? blankcount + 1 : 0;
		}
	} else {
		if (lnblank && fputs(newline, output) == EOF)
			closeout();
		exitstat = 1;
		delcount += 1;
		blankcount = 0;
	}
	if (debugging && fflush(output) == EOF)
		closeout();
}
Beispiel #2
0
main()
  {
  glbptr=startglb;  /* clear global symbols */
  locptr=startloc;  /* clear local symbols */
  wqptr=wq;    /* clear while queue */
  macptr=    /* clear the macro pool */
  litptr=    /* clear literal pool */
    sp =    /* stack ptr (relative) */
  errcnt=    /* no errors */
  eof=    /* not eof yet */
  input=    /* no input file */
  input2=    /* or include file */
  output=    /* no open units */
  ncmp=    /* no open compound states */
  lastst=    /* no last statement yet */
  quote[1]=
  0;    /*  ...all set to zero.... */
  quote[0]='"';    /* fake a quote literal */
  cmode=1;  /* enable preprocessing */
  /*        */
  /*  compiler body    */
  /*        */
  ask();      /* get user options */
  openout();    /* get an output file */
  openin();    /* and initial input file */
  header();    /* intro code */
  parse();     /* process ALL input */
  dumplits();    /* then dump literal pool */
  dumpglbs();    /* and all static memory */
  errorsummary();    /* summarize errors */
  trailer();    /* follow-up code */
  closeout();    /* close the output (if any) */
  return;      /* then exit to system */
  }
Beispiel #3
0
/*
 * The last state transition function. When this is called,
 * lineval == LT_EOF, so the process() loop will terminate.
 */
static void
done(void)
{
	if (incomment)
		error("EOF in comment");
	closeout();
}
Beispiel #4
0
static int
split(int in, int out, char * /* inname */)
{
	int64_t len, membsz;
	uint64_t outoff = 0;
	static Hblock hdr;
	Hblock *hp = &hdr;

	while (getdir(hp, in, &len)) {
		membsz = Tblock + ROUNDUP((uint64_t)len, Tblock);
		if (outoff + membsz + Endsize > size) {	/* won't fit? */
			out = closeout(out, filenm, 1);
			if (membsz + Endsize > size)
				sysfatal("archive member %s (%,lld) + overhead "
					"exceeds size limit %,lld", hp->name,
					len, size);
		}
		if (out < 0)
			out = opennext(out, prefix);
		/* write directory block */
		writetar(out, (char *)hp, Tblock);
		outoff = passtar(hp, in, out, len);
	}
	return out;
}
Beispiel #5
0
void
main(int argc, char **argv)
{
	int out = -1;

	ARGBEGIN {
	case 'p':
		prefix = EARGF(usage());
		break;
	case 's':
		size = atoll(EARGF(usage()));
		if (size < Tblock + Endsize)
			sysfatal("implausible max size of %lld bytes", size);
		break;
	default:
		usage();
	} ARGEND

	if (argc <= 0)
		out = split(Stdin, out, "/fd/0");
	else
		for (; argc-- > 0; argv++) {
			int in = open(argv[0], OREAD);

			if (in < 0)
				sysfatal("%s: %r", argv[0]);
			out = split(in, out, argv[0]);
			close(in);
		}
	closeout(out, filenm, 1);
	exits(0);
}
Beispiel #6
0
void 
#endif

ccabort()
{
        if ( inpt2 != NULL_FD )
                endinclude();
        if ( input != NULL_FD )
                fclose(input);
        closeout();
        fprintf(stderr,"Compilation aborted\n");
        exit(1);
}
Beispiel #7
0
/*
 * Format of #line directives depends on whether we know the input filename.
 */
static void
hashline(void)
{
	int e;

	if (linefile == NULL)
		e = fprintf(output, "#line %d%s", linenum, newline);
	else
		e = fprintf(output, "#line %d \"%s\"%s",
		    linenum, linefile, newline);
	if (e < 0)
		closeout();
}
Beispiel #8
0
static void
done(void)
{
	if (incomment)
		error("EOF in comment");
	closeout();
	if (overwriting && rename(tempname, ofilename) == -1) {
		warn("couldn't rename temporary file");
		unlink(tempname);
		errx(2, "%s unchanged", ofilename);
	}
	exit(exitstat);
}
Beispiel #9
0
/*
 *      Open an include file
 */
void doinclude()
{
        char name[FILENAME_LEN+1], *cp ;

        blanks();       /* skip over to name */
        if (verbose)
        {
        toconsole();
        outstr(line); nl();
        tofile();
        }

        if ( inpt2 )
                error(E_NEST);
        else {
                /* ignore quotes or angle brackets round file name */
                strcpy(name, line+lptr) ;
                cp = name ;
                if ( *cp == '"' || *cp == '<' ) {
                        name[strlen(name)-1] = '\0' ;
                        ++cp ;
                }
                if ( (inpt2=fopen(cp, "r") ) == NULL ) {
                        error(E_INCLUDE) ;
                        closeout();
                        exit(1);
                }
                else {
                        saveline = lineno ;
                        savecurr = currfn ;
                        saveinfn = infunc ;
                        savestart = fnstart ;
                        newfile() ;
                }
        }
        clear();                /* clear rest of line */
                                /* so next read will come from */
                                /* new file (if open) */
}
Beispiel #10
0
static int
ar_getdata(Pax_t* pax, register Archive_t* ap, register File_t* f, int wfd)
{
	register Ar_t*	ar = (Ar_t*)ap->data;

	if (ar->ent->offset < 0)
	{
		error(3, "%s: read not supported for %s format", f->name, ap->format->name);
		return -1;
	}
	if (wfd >= 0)
	{
		if (ardircopy(ar->dir, ar->ent, wfd) < 0)
		{
			error(ERROR_SYSTEM|2, "%s: copy error", f->name);
			return -1;
		}
		closeout(ap, f, wfd);
		setfile(ap, f);
	}
	return 1;
}
Beispiel #11
0
//-------------------------------------------------------------------------------------------------
int main(int argc, char **argv) {
    
    igraph_set_error_handler(igraph_error_handler_printignore);
        igraph_i_set_attribute_table(&igraph_cattribute_table);
    
    
    
    drawingcontrol=1;
	runningcontrol=0;
    cleared=1;
    graphisloaded=0;
	newgraph=1;
    usesteady=0;
    ispii=0;
    haveout=0;
    isrelaxed=0;
    havecstop=0;
    isdissipating=0;
    
    
    
    //RANDOM NUMBER GENERATOR INITIALISE
    init_genrand(0); //srand(3);
    
    
    //preloaded graph:
    {
        latticedim=2;
        latticeside=5;
        istoro=1;
        islattice=1;
        isclustered=0;
        israndomER1=0;
        generatelattice(2,5,1,0,0,0,0);
        //inizializations
        igraph_matrix_init(&state, 0, 0);
        igraph_matrix_init(&density, 0, 0);
        igraph_matrix_init(&densityold,0,0);
        igraph_matrix_init(&statenew, 0, 0);
        igraph_matrix_init(&flux, 0, 0);
        igraph_matrix_init(&loss, 0, 0);
        beginner=(nodesnumber/2);
        InitialStateTAS(beginner,0,totrun);
        igraph_vector_init(&gain,nodesnumber);
        graphisloaded=1;
        newgraph=1;
        haveloadedstate=0;
        
        
        drnodes=1;
        drlinks=1;
        drfluxes=0;
    }
    
    
    
    
    havepath=0;
    sprintf(path,"No path");
  
	
    logDebug("\n DEFAULT ADJ MATRIX:\n");
    print_matrix_ur(&admatrix,stdout);
    printf("\n");
	printf("\n");
    rewrite=1;
    
    CreateMyWindow();
    
    
  //Fl::add_timeout(1.0,mainidle_cb);
  Fl::add_idle(mainidle_cb, 0);
  Fl::run();
    
    
    histdist.Clear();
    
    igraph_destroy(&graph);
    igraph_destroy(&sgraph);
    igraph_matrix_destroy(&admatrix);
    igraph_matrix_destroy(&layout);
    igraph_matrix_destroy(&density);
    igraph_matrix_destroy(&densityold);
    igraph_matrix_destroy(&state);
    igraph_matrix_destroy(&loadedstate);
    igraph_matrix_destroy(&statenew);
    igraph_matrix_destroy(&flux);
    igraph_vector_destroy(&gain);
    igraph_matrix_destroy(&loss);
    igraph_vector_destroy(&statstate);
    igraph_matrix_destroy(&estates);
    
    closeout();
    
  return 0;
}
Beispiel #12
0
int
main(int argc,char **argv)
{
  int option ;
  const char *unzipper = NULL ;
  const char *infile = NULL ;

  setlocale(LC_ALL,"");
  progname = argv[0] ;
  nls_init();

  if( argc <= 1 ) gpl_blurb() ;
  
  init_flatspec(&flatspec) ;
  while( (option=getopt_long(argc,argv,"-"OPTSTRING,longopts,NULL)) >= 0 )
    switch(option) {
      #define OPTION(char,long,desc,man) case char:
      #include "options.i"
    case 1:
      if( infile ) 
        add_layer_request(&flatspec,optarg);
      else
        infile = optarg ;
      break ;
    case '?':
      usage(stderr);
    default:
      FatalUnexpected("Getopt(_long) unexpectedly returned '%c'",option);
    }
  if( infile == NULL ) {
    usage(stderr);
  }
  
  read_or_mmap_xcf(infile,unzipper);
  getBasicXcfInfo() ;
  initColormap();
 
  complete_flatspec(&flatspec,guessIndexed);
  if( flatspec.process_in_memory ) {
    rgba **allPixels = flattenAll(&flatspec);
     
    analyse_colormode(&flatspec,allPixels,guessIndexed);

    /* See if we can do alpha compaction.
     */
    if( flatspec.partial_transparency_mode != ALLOW_PARTIAL_TRANSPARENCY &&
        !FULLALPHA(flatspec.default_pixel) &&
        flatspec.out_color_mode != COLOR_INDEXED ) {
      rgba unused = findUnusedColor(allPixels,
                                    flatspec.dim.width,
                                    flatspec.dim.height);
      if( unused && (flatspec.out_color_mode == COLOR_RGB ||
                     degrayPixel(unused) >= 0) ) {
        unsigned x,y ;
        unused = NEWALPHA(unused,0) ;
        for( y=0; y<flatspec.dim.height; y++)
          for( x=0; x<flatspec.dim.width; x++)
            if( allPixels[y][x] == 0 )
              allPixels[y][x] = unused ;
        flatspec.default_pixel = unused ;
      }
    }
    shipoutWithCallback(&flatspec,allPixels,selectCallback());
  } else {
    flattenIncrementally(&flatspec,selectCallback());
  }
  if( libpng ) {
    png_write_end(libpng,libpng2);
    png_destroy_write_struct(&libpng,&libpng2);
  }
  if( outfile ) {
    closeout(outfile,flatspec.output_filename);
  }
  return 0 ;
}
Beispiel #13
0
/*
 *      Compiler begins execution here
 */
int main(int argc, char **argv)
{
        int     n;      /* Loop counter */
		int     i;
        gargc = argc ;
        gargv = argv ;
/*
 * Empty our mem ptrs
 */

        litq=dubq=tempq=glbq=0;
        symtab=loctab=0;
        wqueue=0;membptr=0;tagptr=0;swnext=0;stage=0;
        gotoq=0;

        /* allocate space for arrays */
        litq = mymalloc(FNLITQ) ;         /* literals, these 2 dumped end */
        dubq = mymalloc(FNLITQ) ;         /* Doubles */
        tempq = mymalloc(LITABSZ) ;        /* Temp strings... */
        glbq  = mymalloc(LITABSZ) ;        /* Used for glb lits, dumped now */
        symtab = SYM_CAST mymalloc(NUMGLBS*sizeof(SYMBOL)) ;
        loctab = SYM_CAST mymalloc(NUMLOC*sizeof(SYMBOL)) ;
        wqueue = WQ_CAST mymalloc(NUMWHILE*sizeof(WHILE_TAB)) ;
        gotoq= (GOTO_TAB *)calloc(NUMGOTO,sizeof(GOTO_TAB));
   if (gotoq==NULL) OutOfMem();

        tagptr = tagtab = TAG_CAST mymalloc(NUMTAG*sizeof(TAG_SYMBOL)) ;
        membptr = membtab = SYM_CAST mymalloc(NUMMEMB*sizeof(SYMBOL)) ;

        swnext = SW_CAST mymalloc(NUMCASE*sizeof(SW_TAB)) ;
        swend = swnext + (NUMCASE-1) ;

        stage = mymalloc(STAGESIZE) ;
        stagelast = stage+STAGELIMIT ;

        /* empty symbol table */
        glbptr = STARTGLB;
        while ( glbptr < ENDGLB ) {
                glbptr->name[0] = 0 ;
                ++glbptr ;
        }

        glbcnt = 0 ;                    /* clear global symbols */
        locptr = STARTLOC ;             /* clear local symbols */
        wqptr = wqueue ;                /* clear while queue */
        gltptr=dubptr=0 ;               /* clear literal pools */
        *litq=0;         /* First entry in literal queue is zero */
        litptr=1;       /* So miniprintf search works */

        Zsp =                   /* stack ptr (relative) */
        errcnt =                /* no errors */
        errstop =               /* keep going after an error */
        eof =                   /* not eof yet */
        swactive =              /* not in switch */
        skiplevel =             /* #if not encountered */
        iflevel =               /* #if nesting level = 0 */
        ncmp =                  /* no open compound states */
        lastst =                /* not first file to asm */
        fnstart =               /* current "function" started at line 0 */
        lineno =                /* no lines read from file */
        infunc =                /* not in function now */
                        0 ;             /*  ...all set to zero.... */

        stagenext = NULL_CHAR ; /* direct output mode */

        input =                                 /* no input file */
        inpt2 =                                 /* or include file */
        saveout =                               /* no diverted output */
        output = NULL_FD ;              /* no open units */

        currfn = NULL_SYM ;             /* no function yet */
        macptr = cmode = 1 ;    /* clear macro pool and enable preprocessing */
        ncomp=doinline=mathz88 = incfloat= compactcode =0;
        intuition=zorg=lpointer=cppcom=appz88=0;
        dosigned=NO;
        makelib=useshare=makeshare=sharedfile=NO;
        smartprintf=expanded=YES;
        startup=0;                      /* Which startup do we want? */
        nxtlab =                        /* start numbers at lowest possible */
        ctext =                         /* don't include the C text as comments */
        errstop =                       /* don't stop after errors */
        verbose = 0;
        gotocnt=0;
   defdenums=0;
   doublestrings = 0;
   noaltreg = NO;
        safedata=reqpag = -1;
   shareoffset=SHAREOFFSET;   /* Offset for shared libs */
   debuglevel=NO;
   farheapsz=-1;         /* Size of far heap */
    assemtype = ASM_Z80ASM;
   printflevel=0;
#ifdef USEFRAME
   indexix=YES;
   useframe=NO;
#endif

        /*
         *      compiler body
         */
        setup_sym() ;   /* define some symbols */
/* Parse the command line options */
        atexit(MemCleanup);     /* To free everything */
        clear();
        filenum=0;
        for (n=1;n<argc;n++) {
                if (argv[n][0]=='-') ParseArgs(1+argv[n]);
                else {filenum=n; break;}
        }
        clear();

        if (filenum == 0)
        {
                info();
                exit(1);
        }
        litlab=getlabel();              /* Get labels for function lits*/
        dublab=getlabel();              /* and fn doubles*/
        openout();              /* get the output file */
        openin();               /* and initial input file */
        header();               /* intro code */
        parse();                /* process ALL input */
        /* dump literal queues, with label */
        /* litq starts from 1, so literp has to be -1 */
        dumplits(0, YES,litptr-1,litlab,litq+1) ;
        dumplits(1, YES,dubptr,dublab,dubq) ;
        dumpvars();
        dumpfns();
        trailer();              /* follow-up code */
        closeout();
        errsummary();   /* summarize errors */
        if (errcnt) exit(1);
        exit(0);
}
Beispiel #14
0
void
filein(register Archive_t* ap, register File_t* f)
{
	register off_t	c;
	register int	n;
	register char*	s;
	int		dfd;
	int		wfd;
	long		checksum;
	Filter_t*	fp;
	Proc_t*		pp;
	Tv_t		t1;
	Tv_t		t2;
	struct stat	st;

	if (f->skip)
		goto skip;
	else if (state.list)
	{
		if (fp = filter(ap, f))
		{
			for (n = 0; s = fp->argv[n]; n++)
			{
				while (*s)
					if (*s++ == '%' && *s == '(')
						break;
				if (*s)
				{
					s = fp->argv[n];
					listprintf(state.tmp.str, ap, f, s);
					if (!(fp->argv[n] = sfstruse(state.tmp.str)))
						nospace();
					break;
				}
			}
			pp = procopen(*fp->argv, fp->argv, NiL, NiL, PROC_WRITE);
			if (s)
				fp->argv[n] = s;
			if (!pp)
			{
				error(2, "%s: %s: cannot execute filter %s", ap->name, f->path, *fp->argv);
				goto skip;
			}
			if (!ap->format->getdata || !(*ap->format->getdata)(&state, ap, f, pp->wfd))
			{
				checksum = 0;
				for (c = f->st->st_size; c > 0; c -= n)
				{
					n = (c > state.buffersize) ? state.buffersize : c;
					if (!(s = bget(ap, n, NiL)))
					{
						error(ERROR_SYSTEM|2, "%s: read error", f->name);
						break;
					}
					if (write(pp->wfd, s, n) != n)
					{
						error(ERROR_SYSTEM|2, "%s: write error", f->name);
						break;
					}
					if (ap->format->checksum)
						checksum = (*ap->format->checksum)(&state, ap, f, s, n, checksum);
				}
			}
			if (ap->format->checksum && checksum != f->checksum)
				error(1, "%s: %s checksum error (0x%08x != 0x%08x)", f->name, ap->format->name, checksum, f->checksum);
			/*
			 * explicitly ignore exit status
			 */

			procclose(pp);
			return;
		}
		listentry(f);
		goto skip;
	}
	else switch (f->delta.op)
	{
	case DELTA_create:
		if (f->delta.base)
			error(3, "%s: base archive mismatch [%s#%d]", f->name, __FILE__, __LINE__);
		if (ap->delta->format->flags & PSEUDO)
			goto regular;
		if ((wfd = openout(ap, f)) < 0)
			goto skip;
		else
			paxdelta(NiL, ap, f, DELTA_TAR|DELTA_FD|DELTA_FREE|DELTA_OUTPUT|DELTA_COUNT, wfd, DELTA_DEL|DELTA_BIO|DELTA_SIZE, ap, f->st->st_size, 0);
		break;
	case DELTA_update:
		if (!f->delta.base || (unsigned long)f->delta.base->mtime.tv_sec >= (unsigned long)f->st->st_mtime)
			error(3, "%s: base archive mismatch [%s#%d]", f->name, __FILE__, __LINE__);
		c = f->st->st_size;
		if ((wfd = openout(ap, f)) < 0)
			goto skip;
		if (state.ordered)
		{
			if (!f->delta.base->uncompressed)
				paxdelta(NiL, ap, f, DELTA_SRC|DELTA_BIO|DELTA_SIZE, ap->delta->base, f->delta.base->size, DELTA_TAR|DELTA_FD|DELTA_FREE|DELTA_OUTPUT|DELTA_COUNT, wfd, DELTA_DEL|DELTA_BIO|DELTA_SIZE, ap, c, 0);
			else if (!paxdelta(NiL, ap, f, DELTA_DEL|DELTA_BIO|DELTA_SIZE, ap->delta->base, f->delta.base->size, DELTA_TAR|DELTA_TEMP|DELTA_OUTPUT, &dfd, 0))
				paxdelta(NiL, ap, f, DELTA_SRC|DELTA_FD|DELTA_SIZE|DELTA_FREE, dfd, f->delta.base->uncompressed, DELTA_TAR|DELTA_FD|DELTA_FREE|DELTA_OUTPUT|DELTA_COUNT, wfd, DELTA_DEL|DELTA_BIO|DELTA_SIZE, ap, c, 0);
		}
		else if (!f->delta.base->uncompressed)
			paxdelta(NiL, ap, f, DELTA_SRC|DELTA_FD|DELTA_OFFSET|DELTA_SIZE, ap->delta->base->io->fd, f->delta.base->offset, f->delta.base->size, DELTA_TAR|DELTA_FD|DELTA_FREE|DELTA_OUTPUT|DELTA_COUNT, wfd, DELTA_DEL|DELTA_BIO|DELTA_SIZE, ap, c, 0);
		else if (!paxdelta(NiL, ap, f, DELTA_DEL|DELTA_FD|DELTA_OFFSET|DELTA_SIZE, ap->delta->base->io->fd, f->delta.base->offset, f->delta.base->size, DELTA_TAR|DELTA_TEMP|DELTA_OUTPUT, &dfd, 0))
			paxdelta(NiL, ap, f, DELTA_SRC|DELTA_FD|DELTA_SIZE|DELTA_FREE, dfd, f->delta.base->uncompressed, DELTA_TAR|DELTA_FD|DELTA_FREE|DELTA_OUTPUT|DELTA_COUNT, wfd, DELTA_DEL|DELTA_BIO|DELTA_SIZE, ap, c, 0);
		break;
	case DELTA_verify:
		if (!f->delta.base || f->delta.base->mtime.tv_sec != f->st->st_mtime)
			error(3, "%s: base archive mismatch [%s#%d]", f->name, __FILE__, __LINE__);
		if ((*state.statf)(f->name, &st))
			error(2, "%s: not copied from base archive", f->name);
		else if (st.st_size != f->delta.base->size || state.modtime && tvcmp(tvmtime(&t1, &st), tvmtime(&t2, f->st)))
			error(1, "%s: changed from base archive", f->name);
		break;
	case DELTA_delete:
		if (!f->delta.base)
			error(3, "%s: base archive mismatch [%s#%d]", f->name, __FILE__, __LINE__);
		/*FALLTHROUGH*/
	default:
	regular:
		wfd = openout(ap, f);
		if (wfd >= 0)
		{
			holeinit(wfd);
			if (!ap->format->getdata || !(*ap->format->getdata)(&state, ap, f, wfd))
			{
				checksum = 0;
				for (c = f->st->st_size; c > 0; c -= n)
				{
					n = (c > state.buffersize) ? state.buffersize : c;
					if (!(s = bget(ap, n, NiL)))
					{
						error(ERROR_SYSTEM|2, "%s: read error", f->name);
						break;
					}
					if (holewrite(wfd, s, n) != n)
					{
						error(ERROR_SYSTEM|2, "%s: write error", f->name);
						break;
					}
					if (ap->format->checksum)
						checksum = (*ap->format->checksum)(&state, ap, f, s, n, checksum);
				}
			}
			holedone(wfd);
			closeout(ap, f, wfd);
			setfile(ap, f);
			if (ap->format->checksum && checksum != f->checksum)
				error(1, "%s: %s checksum error (0x%08x != 0x%08x)", f->name, ap->format->name, checksum, f->checksum);
		}
		else if (ap->format->getdata)
			(*ap->format->getdata)(&state, ap, f, wfd);
		else
		{
			if (wfd < -1)
				listentry(f);
			goto skip;
		}
		break;
	}
	listentry(f);
	return;
 skip:
	fileskip(ap, f);
}
Beispiel #15
0
int fromuupcspool(void)
{
  time_t timer;
  static DIR *dd;
  struct dirent *df;
  char * p;
  FILE * fin;
  int r, lck, savein;
  static char lckname[SSIZE];

  strcpy(lckname, spool_dir);
  strcat(lckname, "locks.lck");
  mkdir(lckname);
  strcat(lckname, PATHSTR);
  strcat(lckname, remote);
  strcat(lckname, ".lck");
  if (access(lckname, 0)==0)
  { if (unlink(lckname))
    { logwrite('!', "System %s locked!\n", remote);
      return 1;
    }
    else
      logwrite('!', "Old lck-flag for %s deleted\n", remote);
  }
  lck=open(lckname, O_BINARY|O_CREAT|O_RDWR|O_EXCL, S_IREAD|S_IWRITE);
  if ((lck==-1) && (errno==EACCES))
  { /* access denied */
    logwrite('!', "System %s locked!\n", remote);
    return 1;
  }
  funix=1;
  if (lck==-1)
    logwrite('!', "Can't create %s: %s!\n", lckname, strerror(errno));
  else
  { time(&timer);
    sprintf(str, "Locked by " NAZVA " PID %u since %s",
            getpid(), ctime(&timer));
    write(lck, str, strlen(str));
    /* flush */
    r=lck;
    lck=dup(r);
    close(r);
  }
  strcpy(str, spool_dir);
  strcpy(named, str);
  strcat(str, remote);
  debug(5, "GetSpool started, spooldir is %s", str);
  strcat(str, "\\c");
  namec[0]=0;
  dd=opendir(str);
  if (dd==NULL)
  { debug(2, "GetSpool: can't opendir %s: %s", str, strerror(errno));
    if (lck!=-1)
    { close(lck);
      unlink(lckname);
    }
    return 0;
  }
  while ((df=readdir(dd))!=NULL)
  { if (df->d_name[0]=='.') continue;
    strcpy(str, spool_dir);
    strcat(str, remote);
    strcat(str, "\\c\\");
    strcat(str, df->d_name);
    fin=myfopen(str, "r");
    if (fin==NULL)
    { logwrite('?', "Can't open %s: %s!\n", str, strerror(errno));
      continue;
    }
    strcpy(namec, str);
    /* там должно быть 2 строки */
    if (!fgets(str, sizeof(str), fin))
    {
badc: fclose(fin);
badc1:strcpy(str, spool_dir);
      strcat(str, "bad.job");
      mkdir(str);
      strcat(str, strrchr(namec,'\\'));
      if (rename(namec, str))
      { logwrite('?',"Can't move %s to %s: %s!\n",namec,str,strerror(errno));
        unlink(namec);
      }
      else
        logwrite('?',"Incorrect spool-file %s, moved to bad.job!\n",namec);
      namec[0]=0;
      continue;
    }
    if (strncmp(str, "S ", 2))
      goto badc;
    /* потом идут имена файлов здесь и там */
    p=strchr(str+2,' ');
    if (p==NULL) goto badc;
    *p=0;
    if (*(p+1)!='D') goto badc;
    strcpy(named, spool_dir);
    importpath(named+strlen(named),str+2,remote);
    if (!fgets(str,sizeof(str),fin))
      goto badc;
    if (strncmp(str, "S ", 2)) /* начинаться должно с "S " */
      goto badc;
    p=strchr(str+2,' ');
    if (p==NULL) goto badc;
    *p=0;
    if (*(p+1)!='X') goto badc;
    strcpy(namex, spool_dir);
    importpath(namex+strlen(namex),str+2,remote);
    if (access(named,0))
    { logwrite('?',"Can't find %s!\n",named);
      goto badc;
    }
    if (access(namex,0))
    { logwrite('?',"Can't find %s!\n",namex);
      goto badc;
    }
    fclose(fin);
    debug(4,"GetSpool: namec=%s, named=%s, namex=%s",namec,named,namex);

    fromaddr[0]=0;
    packnews=0;
    if (fout)
    { if (packmail)
        begdel=ftell(fout);
      else
      { closeout();
        begdel=0;
      }
    }
    else
      begdel=0;

    fin=myfopen(namex,"rb");
    if (fin==NULL)
    { logwrite('?',"Can't open %s: %s!\n",namex,strerror(errno));
      if (lck!=-1)
      { close(lck);
        unlink(lckname);
      }
      return 2;
    }
    while (fgets(str,sizeof(str),fin))
      if (strncmp(str,"C ",2)==0)
        break;
    if (feof(fin))
      goto badc;
    fclose(fin);
    p=strchr(str, '\n');
    if (p) *p='\0';
    r=open(named, O_BINARY|O_RDONLY);
    if (r==-1)
    { logwrite('?', "Can't open %s: %s!\n", named, strerror(errno));
      goto badc1;
    }
    savein=dup(fileno(stdin));
    dup2(r, fileno(stdin));
    close(r); 
    if (strncmp(str+2, "rmail ", 6)==0)
    { char *addrlist;
      if (nonet) continue;
      addrlist=strdup(str+8);
      if (addrlist==NULL)
      { logwrite('?',"Not enough memory!\n");
        r=-1;
      }
      else
      { if (conf)
        { closeout();
          begdel=packnews=0;
        }
        r=rmailfunc(addrlist);
      }
    }
    else if (strcmp(str+2, "rbmail")==0)
    { if (nonet) continue;
      if (conf) 
      { closeout();
        begdel=packnews=0;
      }
      r=rbmail();
    }
    else if (strcmp(str+2, "rcbmail")==0 ||
             strcmp(str+2, "rzbmail")==0)
    { if (nonet) continue;
      if (conf) 
      { closeout();
        begdel=packnews=0;
      }
      r=rcbmail();
    }
    else if (strcmp(str+2, "rnews")==0)
    { if (noecho) continue;
      if (!conf)
      { closeout();
        begdel=packnews=0;
      }
      r=rnews();
    }
    else
    { logwrite('?', "Unknown command '%s' in spool-file!\n", str);
      dup2(savein, fileno(stdin));
      close(savein);
      goto badc1;
    }
    dup2(savein, fileno(stdin));
    close(savein);
    if (r==0)
    { unlink(named);
      unlink(namex);
      unlink(namec);
    }
    else
    { badnews();
      /* goto badc; */
      continue;
    }
  }
  debug(4,"GetSpool: no more jobs in spool");
  closedir(dd);
  if (lck!=-1)
  { close(lck);
    unlink(lckname);
  }
  if (!conf) closeout();
  return 0;
}
Beispiel #16
0
int
copyinout(Ftw_t* ftw)
{
	register File_t*	f = &state.out->file;
	register char*		s;
	register off_t		c;
	register ssize_t	n;
	register int		rfd;
	register int		wfd;

	if (getfile(state.out, f, ftw) && selectfile(state.out, f))
	{
		s = f->name;
		f->name = stash(&state.out->path.copy, NiL, state.pwdlen + f->namesize);
		strcpy(stpcpy(f->name, state.pwd), s + (*s == '/'));
		if ((wfd = openout(state.out, f)) >= 0)
		{
			if ((rfd = openin(state.out, f)) >= 0)
			{
#if defined(SEEK_DATA) && defined(SEEK_HOLE)
				off_t		data;
				off_t		hole;
				int		more;

				data = 0;
				more = 1;
				while (more)
				{
					if ((hole = lseek(rfd, data, SEEK_HOLE)) < data)
					{
						hole = lseek(rfd, 0, SEEK_END);
						more = 0;
					}
					while ((c = hole - data) > 0)
					{
						if (c > state.buffersize)
							c = state.buffersize;
						if (lseek(rfd, data, SEEK_SET) != data || (n = read(rfd, state.tmp.buffer, (size_t)c)) <= 0)
						{
							error(ERROR_SYSTEM|2, "%s: read error", f->name);
							more = 0;
							break;
						}
						if (lseek(wfd, data, SEEK_SET) != data || write(wfd, state.tmp.buffer, n) != n)
						{
							error(ERROR_SYSTEM|2, "%s: write error", f->name);
							more = 0;
							break;
						}
						state.out->io->count += n;
						data += n;
					}
					if (!more)
						break;
					if ((data = lseek(rfd, hole, SEEK_DATA)) < hole)
					{
						if ((data = lseek(rfd, -1, SEEK_END)) < 0 || (data + 1) > hole && (lseek(wfd, data, SEEK_SET) != data || write(wfd, "", 1) != 1))
							error(ERROR_SYSTEM|2, "%s: write error", f->name);
						state.out->io->count += 1;
						break;
					}
				}
#else
				holeinit(wfd);
				for (c = f->st->st_size; c > 0; c -= n)
				{
					if ((n = read(rfd, state.tmp.buffer, (size_t)((c > state.buffersize) ? state.buffersize : c))) <= 0)
					{
						error(ERROR_SYSTEM|2, "%s: read error", f->name);
						break;
					}
					if (holewrite(wfd, state.tmp.buffer, n) != n)
					{
						error(ERROR_SYSTEM|2, "%s: write error", f->name);
						break;
					}
					state.out->io->count += n;
				}
				holedone(wfd);
#endif
				closeout(state.out, f, wfd);
				closein(state.out, f, rfd);
				setfile(state.out, f);
				listentry(f);
			}
			else
				closeout(state.out, f, wfd);
		}
		else if (wfd != -1)
			listentry(f);
	}
	return 0;
}
Beispiel #17
0
int
main(int argc,char **argv)
{
  int option ;
  const char *unzipper = NULL ;
  const char *infile = NULL ;

  setlocale(LC_ALL,"");
  progname = argv[0] ;
  nls_init();

  if( argc <= 1 ) gpl_blurb() ;
  
  init_flatspec(&flatspec) ;
  flatspec.out_color_mode = COLOR_BY_FILENAME ;
  while( (option=getopt_long(argc,argv,"-@#"OPTSTRING,longopts,NULL)) >= 0 )
    switch(option) {
      #define OPTION(char,long,desc,man) case char:
      #include "options.i"
    case 1:
      if( infile ) 
        add_layer_request(&flatspec,optarg);
      else
        infile = optarg ;
      break ;
    case '?':
      usage(stderr);
    case '@':
      /* Non-documented option for build-time test */
      suppress_byline = 1 ;
      break ;
    case '#':
      /* Non-documented option for xcfview */
      flatspec.default_pixel = CHECKERED_BACKGROUND ;
      break ;
    default:
      FatalUnexpected("Getopt(_long) unexpectedly returned '%c'",option);
    }
  if( infile == NULL ) {
    usage(stderr);
  }

  if( flatspec.out_color_mode == COLOR_BY_FILENAME &&
      strlen(flatspec.output_filename) > 4 &&
      flatspec.output_filename[strlen(flatspec.output_filename)-4] == '.' )
    flatspec.out_color_mode = guess_color_mode(flatspec.output_filename);

  /* If the output filename was not enough cue, see if we're running
   * through a symlink/hardlink that gives the required output format
   */
  if( flatspec.out_color_mode == COLOR_BY_FILENAME &&
      strlen(progname) > 3 )
    flatspec.out_color_mode = guess_color_mode(progname);
  
  if( flatspec.out_color_mode == COLOR_BY_FILENAME )
    flatspec.out_color_mode = COLOR_BY_CONTENTS ;
  
  read_or_mmap_xcf(infile,unzipper);
  getBasicXcfInfo() ;
  initColormap();
 
  complete_flatspec(&flatspec,NULL);
  if( flatspec.process_in_memory ) {
    rgba **allPixels = flattenAll(&flatspec);
    analyse_colormode(&flatspec,allPixels,NULL);
    shipoutWithCallback(&flatspec,allPixels,selectCallback());
  } else {
    flattenIncrementally(&flatspec,selectCallback());
  }
  closeout(outfile,flatspec.output_filename) ;
  closeout(transfile,flatspec.transmap_filename) ;
  return 0 ;
}