Beispiel #1
0
void Macro::expand(OutBuffer *buf, unsigned start, unsigned *pend,
                   unsigned char *arg, unsigned arglen)
{
#if 0
    printf("Macro::expand(buf[%d..%d], arg = '%.*s')\n", start, *pend, arglen, arg);
    printf("Buf is: '%.*s'\n", *pend - start, buf->data + start);
#endif

    static int nest;
    if (nest > 100)		// limit recursive expansion
        return;
    nest++;

    unsigned end = *pend;
    assert(start <= end);
    assert(end <= buf->offset);

    /* First pass - replace $0
     */
    arg = memdup(arg, arglen);
    for (unsigned u = start; u + 1 < end; )
    {
        unsigned char *p = buf->data;	// buf->data is not loop invariant

        /* Look for $0, but not $$0, and replace it with arg.
         */
        if (p[u] == '$' && (isdigit(p[u + 1]) || p[u + 1] == '+'))
        {
            if (u > start && p[u - 1] == '$')
            {   // Don't expand $$0, but replace it with $0
                buf->remove(u - 1, 1);
                end--;
                u += 1;	// now u is one past the closing '1'
                continue;
            }

            unsigned char c = p[u + 1];
            int n = (c == '+') ? -1 : c - '0';

            unsigned char *marg;
            unsigned marglen;
            extractArgN(arg, arglen, &marg, &marglen, n);
            if (marglen == 0)
            {   // Just remove macro invocation
                //printf("Replacing '$%c' with '%.*s'\n", p[u + 1], marglen, marg);
                buf->remove(u, 2);
                end -= 2;
            }
            else if (c == '+')
            {
                // Replace '$+' with 'arg'
                //printf("Replacing '$%c' with '%.*s'\n", p[u + 1], marglen, marg);
                buf->remove(u, 2);
                buf->insert(u, marg, marglen);
                end += marglen - 2;

                // Scan replaced text for further expansion
                unsigned mend = u + marglen;
                expand(buf, u, &mend, NULL, 0);
                end += mend - (u + marglen);
                u = mend;
            }
            else
            {
                // Replace '$1' with '\xFF{arg\xFF}'
                //printf("Replacing '$%c' with '\xFF{%.*s\xFF}'\n", p[u + 1], marglen, marg);
                buf->data[u] = 0xFF;
                buf->data[u + 1] = '{';
                buf->insert(u + 2, marg, marglen);
                buf->insert(u + 2 + marglen, "\xFF}", 2);
                end += -2 + 2 + marglen + 2;

                // Scan replaced text for further expansion
                unsigned mend = u + 2 + marglen;
                expand(buf, u + 2, &mend, NULL, 0);
                end += mend - (u + 2 + marglen);
                u = mend;
            }
            //printf("u = %d, end = %d\n", u, end);
            //printf("#%.*s#\n", end, &buf->data[0]);
            continue;
        }

        u++;
    }

    /* Second pass - replace other macros
     */
    for (unsigned u = start; u + 4 < end; )
    {
        unsigned char *p = buf->data;	// buf->data is not loop invariant

        /* A valid start of macro expansion is $(c, where c is
         * an id start character, and not $$(c.
         */
        if (p[u] == '$' && p[u + 1] == '(' && isidstart(p[u + 2]))
        {
            //printf("\tfound macro start '%c'\n", p[u + 2]);
            unsigned char *name = p + u + 2;
            unsigned namelen = 0;

            unsigned char *marg;
            unsigned marglen;

            unsigned v;
            /* Scan forward to find end of macro name and
             * beginning of macro argument (marg).
             */
            for (v = u + 2; v < end; v++)
            {   unsigned char c = p[v];

                if (!isidchar(c))
                {   // We've gone past the end of the macro name.
                    namelen = v - (u + 2);
                    break;
                }
            }

            v += extractArgN(p + v, end - v, &marg, &marglen, 0);
            assert(v <= end);

            if (v < end)
            {   // v is on the closing ')'
                if (u > start && p[u - 1] == '$')
                {   // Don't expand $$(NAME), but replace it with $(NAME)
                    buf->remove(u - 1, 1);
                    end--;
                    u = v;	// now u is one past the closing ')'
                    continue;
                }

                Macro *m = search(name, namelen);
                if (m)
                {
#if 0
                    if (m->textlen && m->text[0] == ' ')
                    {   m->text++;
                        m->textlen--;
                    }
#endif
                    if (m->inuse && marglen == 0)
                    {   // Remove macro invocation
                        buf->remove(u, v + 1 - u);
                        end -= v + 1 - u;
                    }
                    else if (m->inuse && arglen == marglen && memcmp(arg, marg, arglen) == 0)
                    {   // Recursive expansion; just leave in place

                    }
                    else
                    {
                        //printf("\tmacro '%.*s'(%.*s) = '%.*s'\n", m->namelen, m->name, marglen, marg, m->textlen, m->text);
#if 1
                        marg = memdup(marg, marglen);
                        // Insert replacement text
                        buf->spread(v + 1, 2 + m->textlen + 2);
                        buf->data[v + 1] = 0xFF;
                        buf->data[v + 2] = '{';
                        memcpy(buf->data + v + 3, m->text, m->textlen);
                        buf->data[v + 3 + m->textlen] = 0xFF;
                        buf->data[v + 3 + m->textlen + 1] = '}';

                        end += 2 + m->textlen + 2;

                        // Scan replaced text for further expansion
                        m->inuse++;
                        unsigned mend = v + 1 + 2+m->textlen+2;
                        expand(buf, v + 1, &mend, marg, marglen);
                        end += mend - (v + 1 + 2+m->textlen+2);
                        m->inuse--;

                        buf->remove(u, v + 1 - u);
                        end -= v + 1 - u;
                        u += mend - (v + 1);
#else
                        // Insert replacement text
                        buf->insert(v + 1, m->text, m->textlen);
                        end += m->textlen;

                        // Scan replaced text for further expansion
                        m->inuse++;
                        unsigned mend = v + 1 + m->textlen;
                        expand(buf, v + 1, &mend, marg, marglen);
                        end += mend - (v + 1 + m->textlen);
                        m->inuse--;

                        buf->remove(u, v + 1 - u);
                        end -= v + 1 - u;
                        u += mend - (v + 1);
#endif
                        mem.free(marg);
                        //printf("u = %d, end = %d\n", u, end);
                        //printf("#%.*s#\n", end - u, &buf->data[u]);
                        continue;
                    }
                }
                else
                {
                    // Replace $(NAME) with nothing
                    buf->remove(u, v + 1 - u);
                    end -= (v + 1 - u);
                    continue;
                }
            }
        }
        u++;
    }
    mem.free(arg);
    *pend = end;
    nest--;
}
Beispiel #2
0
/*
 * Server routine to read requests and process them.
 * Commands are:
 *	Tname	- Transmit file if out of date
 *	Vname	- Verify if file out of date or not
 *	Qname	- Query if file exists. Return mtime & size if it does.
 */
void
server()
{
	char cmdbuf[BUFSIZ];
	register char *cp;

	signal(SIGHUP, cleanup);
	signal(SIGINT, cleanup);
	signal(SIGQUIT, cleanup);
	signal(SIGTERM, cleanup);
	signal(SIGPIPE, cleanup);

	rem = 0;
	oumask = umask(0);
	(void) sprintf(buf, "V%d\n", VERSION);
	(void) write(rem, buf, strlen(buf));

	for (;;) {
		cp = cmdbuf;
		if (read(rem, cp, 1) <= 0)
			return;
		if (*cp++ == '\n') {
			error("server: expected control record\n");
			continue;
		}
		do {
			if (read(rem, cp, 1) != 1)
				cleanup(0);
		} while (*cp++ != '\n' && cp < &cmdbuf[BUFSIZ]);
		*--cp = '\0';
		cp = cmdbuf;
		switch (*cp++) {
		case 'T':  /* init target file/directory name */
			catname = 1;	/* target should be directory */
			goto dotarget;

		case 't':  /* init target file/directory name */
			catname = 0;
		dotarget:
			if (exptilde(target, cp) == NULL)
				continue;
			tp = target;
			while (*tp)
				tp++;
			ack();
			continue;

		case 'R':  /* Transfer a regular file. */
			recvf(cp, S_IFREG);
			continue;

		case 'D':  /* Transfer a directory. */
			recvf(cp, S_IFDIR);
			continue;

		case 'K':  /* Transfer symbolic link. */
			recvf(cp, S_IFLNK);
			continue;

		case 'k':  /* Transfer hard link. */
			hardlink(cp);
			continue;

		case 'E':  /* End. (of directory) */
			*tp = '\0';
			if (catname <= 0) {
				error("server: too many 'E's\n");
				continue;
			}
			tp = stp[--catname];
			*tp = '\0';
			ack();
			continue;

		case 'C':  /* Clean. Cleanup a directory */
			clean(cp);
			continue;

		case 'Q':  /* Query. Does the file/directory exist? */
			query(cp);
			continue;

		case 'S':  /* Special. Execute commands */
			dospecial(cp);
			continue;

#ifdef notdef
		/*
		 * These entries are reserved but not currently used.
		 * The intent is to allow remote hosts to have master copies.
		 * Currently, only the host rdist runs on can have masters.
		 */
		case 'X':  /* start a new list of files to exclude */
			except = bp = NULL;
		case 'x':  /* add name to list of files to exclude */
			if (*cp == '\0') {
				ack();
				continue;
			}
			if (*cp == '~') {
				if (exptilde(buf, cp) == NULL)
					continue;
				cp = buf;
			}
			if (bp == NULL)
				except = bp = expand(makeblock(NAME, cp), E_VARS);
			else
				bp->b_next = expand(makeblock(NAME, cp), E_VARS);
			while (bp->b_next != NULL)
				bp = bp->b_next;
			ack();
			continue;

		case 'I':  /* Install. Transfer file if out of date. */
			opts = 0;
			while (*cp >= '0' && *cp <= '7')
				opts = (opts << 3) | (*cp++ - '0');
			if (*cp++ != ' ') {
				error("server: options not delimited\n");
				return;
			}
			install(cp, opts);
			continue;

		case 'L':  /* Log. save message in log file */
			log(lfp, cp);
			continue;
#endif

		case '\1':
			nerrs++;
			continue;

		case '\2':
			return;

		default:
			error("server: unknown command '%s'\n", cp);
		case '\0':
			continue;
		}
	}
}
Beispiel #3
0
      coherent_fast( std::size_t _buffer_size )
      {
	 expand( _buffer_size );
      }
Beispiel #4
0
        void ModalityConvex::update(Image& image, PatchSet* patchSet, Rect bounds) {

            Ptr<PatchSet> patches = Ptr<PatchSet>(reliablePatchesFilter.empty() ? patchSet : patchSet->filter(*reliablePatchesFilter));

            if (patches->size() < 3) {
                //flush();
                return;
            }

            Mat temp = image.get_float_mask();

            temp.setTo(0);

            if (history.empty()) {
                history.create(image.height(), image.width(), CV_32F);
                history.setTo(0);
            }

            Point2f* points = new Point2f[patches->size()];
            Point2f* hull = NULL;

            Point2f offset = Point2f(image.width() / 2, image.height() / 2) - patchSet->mean_position();

            Point2f mean(0, 0);

            for (int i = 0; i < patches->size(); i++) {
                points[i] = patches->get_position(i) + offset;
            }

            int size = convex_hull(points, patches->size(), &hull);

            for (int i = 0; i < size; i++) {
                mean.x += hull[i].x;
                mean.y += hull[i].y;
            }

            mean.x /= size;
            mean.y /= size;

            Point* hulli = new Point[size];
            Point* hullei = new Point[size];

            for (int i = 0; i < size; i++) {
                hulli[i].x = (int) hull[i].x;
                hulli[i].y = (int) hull[i].y;
            }

            expand(hull, size, mean, margin);

            for (int i = 0; i < size; i++) {
                hullei[i].x = (int) hull[i].x;
                hullei[i].y = (int) hull[i].y;
            }

            fillConvexPoly(temp, hullei, size, Scalar(1 - margin_diminish));
            fillConvexPoly(temp, hulli, size, Scalar(1));

            delete [] points;
            free(hull);
            delete [] hulli;
            delete [] hullei;

            history = history * persistence + temp * (1.0f - persistence);


        }
Beispiel #5
0
void Tmpl::expand()
{
    expand(true);
}
int
main (void)
{
  register const struct ltest *lt;
  char *ep;
  int status = 0;
  int save_errno;

  for (lt = tests; lt->str != NULL; ++lt)
    {
      register long int l;

      errno = 0;
      l = strtol (lt->str, &ep, lt->base);
      save_errno = errno;
      printf ("strtol(\"%s\", , %d) test %u",
	      lt->str, lt->base, (unsigned int) (lt - tests));
      if (l == (long int) lt->expect && *ep == lt->left
	  && save_errno == lt->err)
	puts("\tOK");
      else
	{
	  puts("\tBAD");
	  if (l != (long int) lt->expect)
	    printf("  returns %ld, expected %ld\n",
		   l, (long int) lt->expect);
	  if (lt->left != *ep)
	    {
	      char exp1[5], exp2[5];
	      expand (exp1, *ep);
	      expand (exp2, lt->left);
	      printf ("  leaves '%s', expected '%s'\n", exp1, exp2);
	    }
	  if (save_errno != lt->err)
	    printf ("  errno %d (%s)  instead of %d (%s)\n",
		    save_errno, strerror (save_errno),
		    lt->err, strerror (lt->err));
	  status = 1;
	}
    }

  for (++lt; lt->str != NULL; lt++)
    {
      register unsigned long int ul;

      errno = 0;
      ul = strtoul (lt->str, &ep, lt->base);
      save_errno = errno;
      printf ("strtoul(\"%s\", , %d) test %u",
	      lt->str, lt->base, (unsigned int) (lt - tests));
      if (ul == lt->expect && *ep == lt->left && save_errno == lt->err)
	puts("\tOK");
      else
	{
	  puts ("\tBAD");
	  if (ul != lt->expect)
	    printf ("  returns %lu, expected %lu\n",
		    ul, lt->expect);
	  if (lt->left != *ep)
	    {
	      char exp1[5], exp2[5];
	      expand (exp1, *ep);
	      expand (exp2, lt->left);
	      printf ("  leaves '%s', expected '%s'\n", exp1, exp2);
	    }
	  if (save_errno != lt->err)
	    printf ("  errno %d (%s) instead of %d (%s)\n",
		    save_errno, strerror (save_errno),
		    lt->err, strerror (lt->err));
	  status = 1;
	}
    }

  return status ? EXIT_FAILURE : EXIT_SUCCESS;
}
Beispiel #7
0
static url
search_sub_dirs (url root) {
  url dirs= complete (root * url_wildcard (), "dr");
  return expand (dirs);
}
 // AES-128
 void operator() (const std::array<VAR, 16>& key,
                  std::array<VAR, 176>& w) const {
     expand(key, w);
 }
 // AES-256
 void operator() (const std::array<VAR, 32>& key,
                  std::array<VAR, 240>& w) const {
     expand(key, w);
 }
Beispiel #10
0
void SensorBrowserTreeWidget::expandItem(const QModelIndex &model_index)
{
    expand(mSortFilterProxyModel.mapFromSource(model_index));
}
Beispiel #11
0
time_t periodic_slaac(time_t now, struct dhcp_lease *leases)
{
  struct dhcp_context *context;
  struct dhcp_lease *lease;
  struct slaac_address *slaac;
  time_t next_event = 0;
  
  for (context = daemon->ra_contexts; context; context = context->next)
    if ((context->flags & CONTEXT_RA_NAME))
      break;

  /* nothing configured */
  if (!context)
    return 0;

  while (ping_id == 0)
    ping_id = rand16();

  if (map_rebuild)
    {
      map_rebuild = 0;
      build_subnet_map();
    }

  for (lease = leases; lease; lease = lease->next)
    for (slaac = lease->slaac_address; slaac; slaac = slaac->next)
      {
	/* confirmed or given up? */
	if (slaac->backoff == 0 || slaac->ping_time == 0)
	  continue;
	
	if (difftime(slaac->ping_time, now) <= 0.0)
	  {
	    struct ping_packet *ping;
	    struct sockaddr_in6 addr;
 
	    save_counter(0);
	    ping = expand(sizeof(struct ping_packet));
	    ping->type = ICMP6_ECHO_REQUEST;
	    ping->code = 0;
	    ping->identifier = ping_id;
	    ping->sequence_no = slaac->backoff;
	    
	    memset(&addr, 0, sizeof(addr));
#ifdef HAVE_SOCKADDR_SA_LEN
	    addr.sin6_len = sizeof(struct sockaddr_in6);
#endif
	    addr.sin6_family = AF_INET6;
	    addr.sin6_port = htons(IPPROTO_ICMPV6);
	    addr.sin6_addr = slaac->addr;
	    
	    if (sendto(daemon->icmp6fd, daemon->outpacket.iov_base, save_counter(0), 0,
		       (struct sockaddr *)&addr,  sizeof(addr)) == -1 &&
		errno == EHOSTUNREACH)
	      slaac->ping_time = 0; /* Give up */ 
	    else
	      {
		slaac->ping_time += (1 << (slaac->backoff - 1)) + (rand16()/21785); /* 0 - 3 */
		if (slaac->backoff > 4)
		  slaac->ping_time += rand16()/4000; /* 0 - 15 */
		if (slaac->backoff < 12)
		  slaac->backoff++;
	      }
	  }
	
	if (slaac->ping_time != 0 &&
	    (next_event == 0 || difftime(next_event, slaac->ping_time) >= 0.0))
	  next_event = slaac->ping_time;
      }

  return next_event;
}
Beispiel #12
0
void Rect::expand(const Rect& rect) {
    expand(rect.pt[0]);
    expand(rect.pt[1]);
}
Beispiel #13
0
int
doname(nameblkp p, int reclevel, time_t *tval, int nowait)
{
int errstat;
int okdel1;
int didwork;
int len;
time_t td, td1, tdep, ptime, ptime1;
depblkp q;
depblkp qtemp, suffp, suffp1;
nameblkp p1, p2;
struct shblock *implcom, *explcom;
lineblkp lp;
lineblkp lp1, lp2;
char sourcename[100], prefix[100], temp[100], concsuff[20];
char *stem;
char *pnamep, *p1namep;
chainp allchain, qchain;
char qbuf[QBUFMAX], tgsbuf[QBUFMAX];
wildp wp;
int nproc1;
char *lastslash, *s;

if(p == 0)
	{
	*tval = 0;
	return 0;
	}

if(dbgflag)
	{
	printf("doname(%s,%d)\n",p->namep,reclevel);
	fflush(stdout);
	}

if(p->done > 0)
	{
	*tval = p->modtime;
	return (p->done == 3);
	}

errstat = 0;
tdep = 0;
implcom = 0;
explcom = 0;
ptime = exists(p->namep);
ptime1 = 0;
didwork = NO;
p->done = 1;	/* avoid infinite loops */
nproc1 = nproc;	/* current depth of process stack */

qchain = NULL;
allchain = NULL;

/* define values of Bradford's $$@ and $$/ macros */
for(s = lastslash = p->namep; *s; ++s)
	if(*s == '/')
		lastslash = s;
setvar("$@", p->namep, YES);
setvar("$/", lastslash, YES);


/* expand any names that have embedded metacharacters */

for(lp = p->linep ; lp ; lp = lp->nxtlineblock)
	for(q = lp->depp ; q ; q=qtemp )
		{
		qtemp = q->nxtdepblock;
		expand(q);
		}

/* make sure all dependents are up to date */

for(lp = p->linep ; lp ; lp = lp->nxtlineblock)
	{
	td = 0;
	for(q = lp->depp ; q ; q = q->nxtdepblock)
		if(q->depname)
			{
			errstat += doname(q->depname, reclevel+1, &td1, q->nowait);
			if(dbgflag)
				printf("TIME(%s)=%ld\n",q->depname->namep, td1);
			if(td1 > td)
				td = td1;
			if(ptime < td1)
				qchain = appendq(qchain, q->depname->namep);
			allchain = appendq(allchain, q->depname->namep);
			}
	if(p->septype == SOMEDEPS)
		{
		if(lp->shp)
		     if( ptime<td || (ptime==0 && td==0) || lp->depp==0)
			{
			okdel1 = okdel;
			okdel = NO;
			set3var("@", p->namep);
			setvar("?", mkqlist(qchain,qbuf), YES);
			setvar("^", mkqlist(allchain,tgsbuf), YES);
			qchain = NULL;
			if( !questflag )
				errstat += docom(lp->shp, nowait, nproc1);
			set3var("@", CHNULL);
			okdel = okdel1;
			ptime1 = prestime();
			didwork = YES;
			}
		}

	else	{
		if(lp->shp != 0)
			{
			if(explcom)
				fprintf(stderr, "Too many command lines for `%s'\n",
					p->namep);
			else	explcom = lp->shp;
			}

		if(td > tdep) tdep = td;
		}
	}



/* Look for implicit dependents, using suffix rules */

for(lp = sufflist ; lp ; lp = lp->nxtlineblock)
    for(suffp = lp->depp ; suffp ; suffp = suffp->nxtdepblock)
	{
	pnamep = suffp->depname->namep;
	if(suffix(p->namep , pnamep , prefix))
		{
		(void)srchdir(concat(prefix,"*",temp), NO, (depblkp) NULL);
		for(lp1 = sufflist ; lp1 ; lp1 = lp1->nxtlineblock)
		    for(suffp1=lp1->depp; suffp1 ; suffp1 = suffp1->nxtdepblock)
			{
			p1namep = suffp1->depname->namep;
			if( (p1=srchname(concat(p1namep, pnamep ,concsuff))) &&
			    (p2=srchname(concat(prefix, p1namep ,sourcename))) )
				{
				errstat += doname(p2, reclevel+1, &td, NO);
				if(ptime < td)
					qchain = appendq(qchain, p2->namep);
if(dbgflag) printf("TIME(%s)=%ld\n", p2->namep, td);
				if(td > tdep) tdep = td;
				set3var("*", prefix);
				set3var("<", copys(sourcename));
				for(lp2=p1->linep ; lp2 ; lp2 = lp2->nxtlineblock)
					if(implcom = lp2->shp) break;
				goto endloop;
				}
			}
		}
	}

/* Look for implicit dependents, using pattern matching rules */

len = strlen(p->namep);
for(wp = firstwild ; wp ; wp = wp->next)
	if(stem = wildmatch(wp, p->namep, len) )
		{
		lp = wp->linep;
		for(q = lp->depp; q; q = q->nxtdepblock)
			{
			if(dbgflag>1 && q->depname)
				fprintf(stderr,"check dep of %s on %s\n", p->namep,
					wildsub(q->depname->namep,stem));
			if(q->depname &&
				! chkname(wildsub(q->depname->namep,stem)))
					break;
			}

		if(q)	/* some name not found, go to next line */
			continue;

		for(q = lp->depp; q; q = q->nxtdepblock)
			{
			nameblkp tamep;
			if(q->depname == NULL)
				continue;
			tamep = srchname( wildsub(q->depname->namep,stem));
/*TEMP fprintf(stderr,"check dep %s on %s =>%s\n",p->namep,q->depname->namep,tamep->namep);*/
/*TEMP*/if(dbgflag) printf("%s depends on %s. stem=%s\n", p->namep,tamep->namep, stem);
			errstat += doname(tamep, reclevel+1, &td, q->nowait);
			if(ptime < td)
				qchain = appendq(qchain, tamep->namep);
			allchain = appendq(allchain, tamep->namep);
			if(dbgflag) printf("TIME(%s)=%ld\n", tamep->namep, td);
			if(td > tdep)
				tdep = td;
			set3var("<", copys(tamep->namep) );
			}
		set3var("*", stem);
		setvar("%", stem, YES);
		implcom = lp->shp;
		goto endloop;
		}

endloop:


if(errstat==0 && (ptime<tdep || (ptime==0 && tdep==0) ) )
	{
	ptime = (tdep>0 ? tdep : prestime() );
	set3var("@", p->namep);
	setvar("?", mkqlist(qchain,qbuf), YES);
	setvar("^", mkqlist(allchain,tgsbuf), YES);
	if(explcom)
		errstat += docom(explcom, nowait, nproc1);
	else if(implcom)
		errstat += docom(implcom, nowait, nproc1);
	else if(p->septype == 0)
		if(p1=srchname(".DEFAULT"))
			{
			set3var("<", p->namep);
			for(lp2 = p1->linep ; lp2 ; lp2 = lp2->nxtlineblock)
				if(implcom = lp2->shp)
					{
					errstat += docom(implcom, nowait,nproc1);
					break;
					}
			}
		else if(keepgoing)
			{
			printf("Don't know how to make %s\n", p->namep);
			++errstat;
			}
		else
			fatal1(" Don't know how to make %s", p->namep);

	set3var("@", CHNULL);
	if(noexflag || nowait || (ptime = exists(p->namep)) == 0 )
		ptime = prestime();
	}

else if(errstat!=0 && reclevel==0)
	printf("`%s' not remade because of errors\n", p->namep);

else if(!questflag && reclevel==0  &&  didwork==NO)
	printf("`%s' is up to date.\n", p->namep);

if(questflag && reclevel==0)
	exit(ndocoms>0 ? -1 : 0);

p->done = (errstat ? 3 : 2);
if(ptime1 > ptime)
	ptime = ptime1;
p->modtime = ptime;
*tval = ptime;
return errstat;
}
void FeatureStats::add(FeatureStatsType v)
{
  if (isfull()) expand();
  m_array[m_entries++]=v;
}
Beispiel #15
0
void GLELocalVars::copyFrom(GLELocalVars* other, int nb) {
	expand(nb);
	for (int i = 0; i < nb; i++) {
		values.set(i, other->values.get(i));
	}
}
Beispiel #16
0
/*
 * Do macro expansion in a row of tokens.
 * Flag is NULL if more input can be gathered.
 */
void
    expandrow(Tokenrow * trp, char *flag)
{
    Token * tp;
    Nlist * np;

    MacroValidatorList  validators;
    mvl_init(&validators);
    /* Sets all token-identifiers to 0 because tokens may not be initialised (never use C!) */
    tokenrow_zeroTokenIdentifiers(trp);

    if (flag)
        setsource(flag, -1, -1, "", 0);
    for (tp = trp->tp; tp < trp->lp;)
    {
        mvl_check(&validators, tp);

        if (tp->type != NAME
            || quicklook(tp->t[0], tp->len > 1 ? tp->t[1] : 0) == 0
            || (np = lookup(tp, 0)) == NULL
            || (np->flag & (ISDEFINED | ISMAC)) == 0
            || (np->flag & ISACTIVE) != 0)
        {
            tp++;
            continue;
        }
        trp->tp = tp;
        if (np->val == KDEFINED)
        {
            tp->type = DEFINED;
            if ((tp + 1) < trp->lp && (tp + 1)->type == NAME)
                (tp + 1)->type = NAME1;
            else
                if ((tp + 3) < trp->lp && (tp + 1)->type == LP
                    && (tp + 2)->type == NAME && (tp + 3)->type == RP)
                    (tp + 2)->type = NAME1;
                else
                    error(ERROR, "Incorrect syntax for `defined'");
            tp++;
            continue;
        }
        else
            if (np->val == KMACHINE)
            {
                if (((tp - 1) >= trp->bp) && ((tp - 1)->type == SHARP))
                {
                    tp->type = ARCHITECTURE;
                    if ((tp + 1) < trp->lp && (tp + 1)->type == NAME)
                        (tp + 1)->type = NAME2;
                    else
                        if ((tp + 3) < trp->lp && (tp + 1)->type == LP
                            && (tp + 2)->type == NAME && (tp + 3)->type == RP)
                            (tp + 2)->type = NAME2;
                        else
                            error(ERROR, "Incorrect syntax for `#machine'");
                }
                tp++;
                continue;
            }

        if (np->flag & ISMAC)
            builtin(trp, np->val);
        else
            expand(trp, np, &validators);
        tp = trp->tp;
    }   // end for
    if (flag)
        unsetsource();

    mvl_destruct(&validators);
}
Beispiel #17
0
void mcat(int argc, char **argv, int type)
{
	struct device *dev;
	struct device out_dev;
	char drive, name[EXPAND_BUF];
        char errmsg[200];
        Stream_t *Stream;
	char buf[BUF_SIZE];

	mt_off_t address = 0;

	char mode = O_RDONLY;
	int optindex = 1;
	size_t len;

	noPrivileges = 1;

	if (argc < 2) {
		usage();
	}

	if (argv[1][0] == '-') {
		if (argv[1][1] != 'w') {
			usage();
		}
		mode = O_WRONLY;
		optindex++;
	}

	if (argc - optindex < 1)
		usage();


	if (!argv[optindex][0] || argv[optindex][1] != ':' 
	    || argv[optindex][2]) {
		usage();
	}

        drive = toupper(argv[optindex][0]);

        /* check out a drive whose letter and parameters match */       
        sprintf(errmsg, "Drive '%c:' not supported", drive);    
        Stream = NULL;
        for (dev=devices; dev->name; dev++) {
                FREE(&Stream);
                if (dev->drive != drive)
                        continue;
                out_dev = *dev;
                expand(dev->name,name);
#ifdef USING_NEW_VOLD
                strcpy(name, getVoldName(dev, name));
#endif

                Stream = 0;
#ifdef USE_XDF
                Stream = XdfOpen(&out_dev, name, mode, errmsg, 0);
				if(Stream)
                        out_dev.use_2m = 0x7f;

#endif

#ifdef USE_FLOPPYD
                if(!Stream)
                        Stream = FloppydOpen(&out_dev, dev, name, 
					     mode, errmsg, 0, 1, NULL);
#endif


                if (!Stream)
                        Stream = SimpleFileOpen(&out_dev, dev, name, mode,
						errmsg, 0, 1, 0);

                if( !Stream)
                        continue;
                break;
        }

        /* print error msg if needed */ 
        if ( dev->drive == 0 ){
                FREE(&Stream);
                fprintf(stderr,"%s\n",errmsg);
                exit(1);
        }


	if (mode == O_WRONLY) {
		mt_size_t size=0;
		size = out_dev.sectors * out_dev.heads * out_dev.tracks;
		size *= 512;
		while ((len = fread(buf, 1,
				    bufLen(BUF_SIZE, size, address),
				    stdin)) > 0) {			
			int r = WRITES(Stream, buf, address, len);
			fprintf(stderr, "Wrote to %d\n", (int) address);
			if(r < 0)
				break;
			address += len;
		}
	} else {
		while ((len = READS(Stream, buf, address, BUF_SIZE)) > 0) {
			fwrite(buf, 1, len, stdout);
			address += len;
		}
	}

	FREE(&Stream);
	exit(0);
}
Beispiel #18
0
ProtoTree::ProtoTree(QWidget *parent) :
    QTreeWidget(parent),
    decode_as_(NULL)
{
    QMenu *submenu, *subsubmenu;
    QAction *action;

    setAccessibleName(tr("Packet details"));
    setUniformRowHeights(true);

    // XXX We might want to reimplement setParent() and fill in the context
    // menu there.
    ctx_menu_.addAction(window()->findChild<QAction *>("actionViewExpandSubtrees"));
    ctx_menu_.addAction(window()->findChild<QAction *>("actionViewExpandAll"));
    ctx_menu_.addAction(window()->findChild<QAction *>("actionViewCollapseAll"));
    ctx_menu_.addSeparator();
//    "     <menuitem name='CreateAColumn' action='/Create a Column'/>\n"
    action = window()->findChild<QAction *>("actionApply_as_Filter");
    submenu = new QMenu();
    action->setMenu(submenu);
    ctx_menu_.addAction(action);
    submenu->addAction(window()->findChild<QAction *>("actionAnalyzeAAFSelected"));
    submenu->addAction(window()->findChild<QAction *>("actionAnalyzeAAFNotSelected"));
    submenu->addAction(window()->findChild<QAction *>("actionAnalyzeAAFAndSelected"));
    submenu->addAction(window()->findChild<QAction *>("actionAnalyzeAAFOrSelected"));
    submenu->addAction(window()->findChild<QAction *>("actionAnalyzeAAFAndNotSelected"));
    submenu->addAction(window()->findChild<QAction *>("actionAnalyzeAAFOrNotSelected"));

    action = window()->findChild<QAction *>("actionPrepare_a_Filter");
    submenu = new QMenu();
    action->setMenu(submenu);
    ctx_menu_.addAction(action);
    submenu->addAction(window()->findChild<QAction *>("actionAnalyzePAFSelected"));
    submenu->addAction(window()->findChild<QAction *>("actionAnalyzePAFNotSelected"));
    submenu->addAction(window()->findChild<QAction *>("actionAnalyzePAFAndSelected"));
    submenu->addAction(window()->findChild<QAction *>("actionAnalyzePAFOrSelected"));
    submenu->addAction(window()->findChild<QAction *>("actionAnalyzePAFAndNotSelected"));
    submenu->addAction(window()->findChild<QAction *>("actionAnalyzePAFOrNotSelected"));

//    action = window()->findChild<QAction *>("actionColorize_with_Filter");
//    submenu = new QMenu();
//    action->setMenu(submenu);
//    ctx_menu_.addAction(action);
//    "       <menuitem name='Color1' action='/Colorize with Filter/Color 1'/>\n"
//    "       <menuitem name='Color2' action='/Colorize with Filter/Color 2'/>\n"
//    "       <menuitem name='Color3' action='/Colorize with Filter/Color 3'/>\n"
//    "       <menuitem name='Color4' action='/Colorize with Filter/Color 4'/>\n"
//    "       <menuitem name='Color5' action='/Colorize with Filter/Color 5'/>\n"
//    "       <menuitem name='Color6' action='/Colorize with Filter/Color 6'/>\n"
//    "       <menuitem name='Color7' action='/Colorize with Filter/Color 7'/>\n"
//    "       <menuitem name='Color8' action='/Colorize with Filter/Color 8'/>\n"
//    "       <menuitem name='Color9' action='/Colorize with Filter/Color 9'/>\n"
//    "       <menuitem name='Color10' action='/Colorize with Filter/Color 10'/>\n"
//    "       <menuitem name='NewColoringRule' action='/Colorize with Filter/New Coloring Rule'/>\n"
//    "     </menu>\n"
//    "     <menuitem name='FollowTCPStream' action='/Follow TCP Stream'/>\n"
//    "     <menuitem name='FollowUDPStream' action='/Follow UDP Stream'/>\n"
//    "     <menuitem name='FollowSSLStream' action='/Follow SSL Stream'/>\n"
    ctx_menu_.addSeparator();

    action = window()->findChild<QAction *>("actionCopy");
    submenu = new QMenu();
    action->setMenu(submenu);
    ctx_menu_.addAction(action);
    submenu->addAction(window()->findChild<QAction *>("actionEditCopyDescription"));
    submenu->addAction(window()->findChild<QAction *>("actionEditCopyFieldName"));
    submenu->addAction(window()->findChild<QAction *>("actionEditCopyValue"));
    submenu->addSeparator();
    submenu->addAction(window()->findChild<QAction *>("actionEditCopyAsFilter"));

    action = window()->findChild<QAction *>("actionBytes");
    subsubmenu = new QMenu();
    action->setMenu(subsubmenu);
    submenu->addAction(action);
    subsubmenu->addSeparator();
//    "        <menu name= 'Bytes' action='/Copy/Bytes'>\n"
//    "           <menuitem name='OffsetHexText' action='/Copy/Bytes/OffsetHexText'/>\n"
//    "           <menuitem name='OffsetHex' action='/Copy/Bytes/OffsetHex'/>\n"
//    "           <menuitem name='PrintableTextOnly' action='/Copy/Bytes/PrintableTextOnly'/>\n"
//    "           <separator/>\n"
//    "           <menuitem name='HexStream' action='/Copy/Bytes/HexStream'/>\n"
//    "           <menuitem name='BinaryStream' action='/Copy/Bytes/BinaryStream'/>\n"
//    "        </menu>\n"
//    "     </menu>\n"
//    "     <menuitem name='ExportSelectedPacketBytes' action='/ExportSelectedPacketBytes'/>\n"
//    ctx_menu_.addSeparator();
//    "     <menuitem name='WikiProtocolPage' action='/WikiProtocolPage'/>\n"
//    "     <menuitem name='FilterFieldReference' action='/FilterFieldReference'/>\n"
//    "     <menuitem name='ProtocolHelp' action='/ProtocolHelp'/>\n"
//    "     <menuitem name='ProtocolPreferences' action='/ProtocolPreferences'/>\n"
//    ctx_menu_.addSeparator();
    decode_as_ = window()->findChild<QAction *>("actionAnalyzeDecodeAs");
    ctx_menu_.addAction(decode_as_);
//    "     <menuitem name='DisableProtocol' action='/DisableProtocol'/>\n"
//    "     <menuitem name='ResolveName' action='/ResolveName'/>\n"
//    "     <menuitem name='GotoCorrespondingPacket' action='/GotoCorrespondingPacket'/>\n"

    connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
            this, SLOT(updateSelectionStatus(QTreeWidgetItem*)));
    connect(this, SIGNAL(expanded(QModelIndex)), this, SLOT(expand(QModelIndex)));
    connect(this, SIGNAL(collapsed(QModelIndex)), this, SLOT(collapse(QModelIndex)));
    connect(this, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)),
            this, SLOT(itemDoubleClick(QTreeWidgetItem*, int)));
}
int
main (int argc, char ** argv)
{
  char buf[100];
  register const struct ltest *lt;
  char *ep;
  int status = 0;
  int save_errno;

  for (lt = tests; lt->str != NULL; ++lt)
    {
      double d;

      errno = 0;
      d = strtod(lt->str, &ep);
      save_errno = errno;
      printf ("strtod (\"%s\") test %u",
	     lt->str, (unsigned int) (lt - tests));
      if (d == lt->expect && *ep == lt->left && save_errno == lt->err)
	puts ("\tOK");
      else
	{
	  puts ("\tBAD");
	  if (d != lt->expect)
	    printf ("  returns %.60g, expected %.60g\n", d, lt->expect);
	  if (lt->left != *ep)
	    {
	      char exp1[5], exp2[5];
	      expand (exp1, *ep);
	      expand (exp2, lt->left);
	      printf ("  leaves '%s', expected '%s'\n", exp1, exp2);
	    }
	  if (save_errno != lt->err)
	    printf ("  errno %d (%s)  instead of %d (%s)\n",
		    save_errno, strerror (save_errno),
		    lt->err, strerror (lt->err));
	  status = 1;
	}
    }

  sprintf (buf, "%f", strtod ("-0.0", NULL));
  if (strcmp (buf, "-0.000000") != 0)
    {
      printf ("  strtod (\"-0.0\", NULL) returns \"%s\"\n", buf);
      status = 1;
    }

  const char input[] = "3752432815e-39";

  float f1 = strtold (input, NULL);
  float f2;
  float f3 = strtof (input, NULL);
  sscanf (input, "%g", &f2);

  if (f1 != f2)
    {
      printf ("f1 = %a != f2 = %a\n", f1, f2);
      status = 1;
    }
  if (f1 != f3)
    {
      printf ("f1 = %a != f3 = %a\n", f1, f3);
      status = 1;
    }
  if (f2 != f3)
    {
      printf ("f2 = %a != f3 = %a\n", f2, f3);
      status = 1;
    }

  const char input2[] = "+1.000000000116415321826934814453125";
  if (strtold (input2, NULL) != +1.000000000116415321826934814453125)
    {
      printf ("input2: %La != %La\n", strtold (input2, NULL),
	      +1.000000000116415321826934814453125);
      status = 1;
    }

  status |= long_dbl ();

  status |= locale_test ();

  return status ? EXIT_FAILURE : EXIT_SUCCESS;
}
Beispiel #20
0
void *alloc(u32int size, u8int page_align, heap_t *heap)
{

    // Make sure we take the size of header/footer into account.
    u32int new_size = size + sizeof(header_t) + sizeof(footer_t);
    // Find the smallest hole that will fit.
    s32int iterator = find_smallest_hole(new_size, page_align, heap);

    if (iterator == -1) // If we didn't find a suitable hole
    {
        // Save some previous data.
        u32int old_length = heap->end_address - heap->start_address;
        u32int old_end_address = heap->end_address;

        // We need to allocate some more space.
        expand(old_length+new_size, heap);
        u32int new_length = heap->end_address-heap->start_address;

        // Find the endmost header. (Not endmost in size, but in location).
        iterator = 0;
        // Vars to hold the index of, and value of, the endmost header found so far.
        u32int idx = -1; u32int value = 0x0;
        while (iterator < heap->index.size)
        {
            u32int tmp = (u32int)lookup_ordered_array(iterator, &heap->index);
            if (tmp > value)
            {
                value = tmp;
                idx = iterator;
            }
            iterator++;
        }

        // If we didn't find ANY headers, we need to add one.
        if (idx == -1)
        {
            header_t *header = (header_t *)old_end_address;
            header->magic = HEAP_MAGIC;
            header->size = new_length - old_length;
            header->is_hole = 1;
            footer_t *footer = (footer_t *) (old_end_address + header->size - sizeof(footer_t));
            footer->magic = HEAP_MAGIC;
            footer->header = header;
            insert_ordered_array((void*)header, &heap->index);
        }
        else
        {
            // The last header needs adjusting.
            header_t *header = lookup_ordered_array(idx, &heap->index);
            header->size += new_length - old_length;
            // Rewrite the footer.
            footer_t *footer = (footer_t *) ( (u32int)header + header->size - sizeof(footer_t) );
            footer->header = header;
            footer->magic = HEAP_MAGIC;
        }
        // We now have enough space. Recurse, and call the function again.
        return alloc(size, page_align, heap);
    }

    header_t *orig_hole_header = (header_t *)lookup_ordered_array(iterator, &heap->index);
    u32int orig_hole_pos = (u32int)orig_hole_header;
    u32int orig_hole_size = orig_hole_header->size;
    // Here we work out if we should split the hole we found into two parts.
    // Is the original hole size - requested hole size less than the overhead for adding a new hole?
    if (orig_hole_size-new_size < sizeof(header_t)+sizeof(footer_t))
    {
        // Then just increase the requested size to the size of the hole we found.
        size += orig_hole_size-new_size;
        new_size = orig_hole_size;
    }

    // If we need to page-align the data, do it now and make a new hole in front of our block.
    if (page_align && orig_hole_pos&0xFFFFF000)
    {
        u32int new_location   = orig_hole_pos + 0x1000 /* page size */ - (orig_hole_pos&0xFFF) - sizeof(header_t);
        header_t *hole_header = (header_t *)orig_hole_pos;
        hole_header->size     = 0x1000 /* page size */ - (orig_hole_pos&0xFFF) - sizeof(header_t);
        hole_header->magic    = HEAP_MAGIC;
        hole_header->is_hole  = 1;
        footer_t *hole_footer = (footer_t *) ( (u32int)new_location - sizeof(footer_t) );
        hole_footer->magic    = HEAP_MAGIC;
        hole_footer->header   = hole_header;
        orig_hole_pos         = new_location;
        orig_hole_size        = orig_hole_size - hole_header->size;
    }
    else
    {
        // Else we don't need this hole any more, delete it from the index.
        remove_ordered_array(iterator, &heap->index);
    }

    // Overwrite the original header...
    header_t *block_header  = (header_t *)orig_hole_pos;
    block_header->magic     = HEAP_MAGIC;
    block_header->is_hole   = 0;
    block_header->size      = new_size;
    // ...And the footer
    footer_t *block_footer  = (footer_t *) (orig_hole_pos + sizeof(header_t) + size);
    block_footer->magic     = HEAP_MAGIC;
    block_footer->header    = block_header;

    // We may need to write a new hole after the allocated block.
    // We do this only if the new hole would have positive size...
    if (orig_hole_size - new_size > 0)
    {
        header_t *hole_header = (header_t *) (orig_hole_pos + sizeof(header_t) + size + sizeof(footer_t));
        hole_header->magic    = HEAP_MAGIC;
        hole_header->is_hole  = 1;
        hole_header->size     = orig_hole_size - new_size;
        footer_t *hole_footer = (footer_t *) ( (u32int)hole_header + orig_hole_size - new_size - sizeof(footer_t) );
        if ((u32int)hole_footer < heap->end_address)
        {
            hole_footer->magic = HEAP_MAGIC;
            hole_footer->header = hole_header;
        }
        // Put the new hole in the index;
        insert_ordered_array((void*)hole_header, &heap->index);
    }
    
    // ...And we're done!
    return (void *) ( (u32int)block_header+sizeof(header_t) );
}
Beispiel #21
0
int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length)
{ /* Code 2 of 5 Interleaved */

	int i, j, k, error_number;
	char bars[7], spaces[7], mixed[14], dest[1000];
#ifndef _MSC_VER
	unsigned char temp[length + 2];
#else
	unsigned char* temp = (unsigned char *)_alloca((length + 2) * sizeof(unsigned char));
#endif

	error_number = 0;

	if(length > 89) {
		strcpy(symbol->errtxt, "Input too long");
		return ZINT_ERROR_TOO_LONG;
	}
	error_number = is_sane(NEON, source, length);
	if (error_number == ZINT_ERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}

	ustrcpy(temp, (unsigned char *) "");
	/* Input must be an even number of characters for Interlaced 2 of 5 to work:
	   if an odd number of characters has been entered then add a leading zero */
	if (length & 1)
	{
		ustrcpy(temp, (unsigned char *) "0");
		length++;
	}
	uconcat(temp, source);

	/* start character */
	strcpy(dest, "1111");

	for(i = 0; i < length; i+=2 )
	{
		/* look up the bars and the spaces and put them in two strings */
		strcpy(bars, "");
		lookup(NEON, C25InterTable, temp[i], bars);
		strcpy(spaces, "");
		lookup(NEON, C25InterTable, temp[i + 1], spaces);

		/* then merge (interlace) the strings together */
		k = 0;
		for(j = 0; j <= 4; j++)
		{
			mixed[k] = bars[j]; k++;
			mixed[k] = spaces[j]; k++;
		}
		mixed[k] = '\0';
		concat (dest, mixed);
	}

	/* Stop character */
	concat (dest, "311");

	expand(symbol, dest);
	ustrcpy(symbol->text, temp);
	return error_number;

}
Beispiel #22
0
/**
 * Handle Code 128 and NVE-18.
 */
int code_128(struct zint_symbol *symbol, const uint8_t source[], int length)
{
	int values[170] = { 0 }, bar_characters, read, total_sum;
	int error_number, indexchaine, indexliste, sourcelen, f_state;
	char set[170] = { ' ' }, fset[170] = { ' ' }, mode, last_set, current_set = ' ';
	float glyph_count;
	char dest[1000];

	error_number = 0;
	strcpy(dest, "");

	sourcelen = length;

	bar_characters = 0;
	f_state = 0;

	if(sourcelen > 160) {
		/* This only blocks rediculously long input - the actual length of the
		   resulting barcode depends on the type of data, so this is trapped later */
		strcpy(symbol->errtxt, "Input too long");
		return ZERROR_TOO_LONG;
	}

	/* Detect extended ASCII characters */
	for(int i = 0; i < sourcelen; i++) {
		if(source[i] >= 128)
			fset[i] = 'f';
	}
	fset[sourcelen] = '\0';

	/* Decide when to latch to extended mode - Annex E note 3 */
	int j = 0;
	for(int i = 0; i < sourcelen; i++) {
		if(fset[i] == 'f') {
			j++;
		} else {
			j = 0;
		}

		if(j >= 5) {
			for(int k = i; k > (i - 5); k--) {
				fset[k] = 'F';
			}
		}

		if((j >= 3) && (i == (sourcelen - 1))) {
			for(int k = i; k > (i - 3); k--) {
				fset[k] = 'F';
			}
		}
	}

	/* Decide if it is worth reverting to 646 encodation for a few
	   characters as described in 4.3.4.2 (d) */
	for (int i = 1; i < sourcelen; i++) {
		if((fset[i - 1] == 'F') && (fset[i] == ' ')) {
			/* Detected a change from 8859-1 to 646 - count how long for */
			int j;
			for (j = 0; (fset[i + j] == ' ') && ((i + j) < sourcelen); j++);
			if ((j < 5) || ((j < 3) && ((i + j) == (sourcelen - 1)))) {
				/* Uses the same figures recommended by Annex E note 3 */
				/* Change to shifting back rather than latching back */
				for (int k = 0; k < j; k++) {
					fset[i + k] = 'n';
				}
			}
		}
	}

	/* Decide on mode using same system as PDF417 and rules of ISO 15417 Annex E */
	indexliste = 0;
	indexchaine = 0;

	mode = parunmodd(source[indexchaine]);
	if((symbol->symbology == BARCODE_CODE128B) && (mode == ABORC)) {
		mode = AORB;
	}

	memset(list[0], 0, 170 * sizeof(list[0][0]));

	do {
		list[1][indexliste] = mode;
		while ((list[1][indexliste] == mode) && (indexchaine < sourcelen)) {
			list[0][indexliste]++;
			indexchaine++;
			mode = parunmodd(source[indexchaine]);
			if((symbol->symbology == BARCODE_CODE128B) && (mode == ABORC)) {
				mode = AORB;
			}
		}
		indexliste++;
	} while (indexchaine < sourcelen);

	dxsmooth(&indexliste);

	/* Resolve odd length LATCHC blocks */
	if((list[1][0] == LATCHC) && (list[0][0] & 1)) {
		/* Rule 2 */
		list[0][1]++;
		list[0][0]--;
		if(indexliste == 1) {
			list[0][1] = 1;
			list[1][1] = LATCHB;
			indexliste = 2;
		}
	}
	if (indexliste > 1) {
		for(int i = 1; i < indexliste; i++) {
			if((list[1][i] == LATCHC) && (list[0][i] & 1)) {
				/* Rule 3b */
				list[0][i - 1]++;
				list[0][i]--;
			}
		}
	}

	/* Put set data into set[] */

	read = 0;
	for(int i = 0; i < indexliste; i++) {
		for(int j = 0; j < list[0][i]; j++) {
			switch(list[1][i]) {
			case SHIFTA:
				set[read] = 'a';
				break;
			case LATCHA:
				set[read] = 'A';
				break;
			case SHIFTB:
				set[read] = 'b';
				break;
			case LATCHB:
				set[read] = 'B';
				break;
			case LATCHC:
				set[read] = 'C';
				break;
			}
			read++;
		}
	}

	/* Adjust for strings which start with shift characters - make them latch instead */
	for (int i = 0; set[i] == 'a'; i++)
		set[i] = 'A';

	for (int i = 0; set[i] == 'b'; i++)
		set[i] = 'B';

	/* Now we can calculate how long the barcode is going to be - and stop it from
	   being too long */
	last_set = ' ';
	glyph_count = 0.0;
	for (int i = 0; i < sourcelen; i++) {
		if((set[i] == 'a') || (set[i] == 'b')) {
			glyph_count = glyph_count + 1.0;
		}
		if((fset[i] == 'f') || (fset[i] == 'n')) {
			glyph_count = glyph_count + 1.0;
		}
		if(((set[i] == 'A') || (set[i] == 'B')) || (set[i] == 'C')) {
			if(set[i] != last_set) {
				last_set = set[i];
				glyph_count = glyph_count + 1.0;
			}
		}
		if(i == 0) {
			if(fset[i] == 'F') {
				glyph_count = glyph_count + 2.0;
			}
		} else {
			if((fset[i] == 'F') && (fset[i - 1] != 'F')) {
				glyph_count = glyph_count + 2.0;
			}
			if((fset[i] != 'F') && (fset[i - 1] == 'F')) {
				glyph_count = glyph_count + 2.0;
			}
		}

		if(set[i] == 'C') {
			glyph_count = glyph_count + 0.5;
		} else {
			glyph_count = glyph_count + 1.0;
		}
	}
	if(glyph_count > 80.0) {
		strcpy(symbol->errtxt, "Input too long");
		return ZERROR_TOO_LONG;
	}

	/* So now we know what start character to use - we can get on with it! */
	if(symbol->output_options & READER_INIT) {
		/* Reader Initialisation mode */
		switch(set[0]) {
			case 'A': /* Start A */
				concat(dest, C128Table[103]);
				values[0] = 103;
				current_set = 'A';
				concat(dest, C128Table[96]); /* FNC3 */
				values[1] = 96;
				bar_characters++;
				break;
			case 'B': /* Start B */
				concat(dest, C128Table[104]);
				values[0] = 104;
				current_set = 'B';
				concat(dest, C128Table[96]); /* FNC3 */
				values[1] = 96;
				bar_characters++;
				break;
			case 'C': /* Start C */
				concat(dest, C128Table[104]); /* Start B */
				values[0] = 105;
				concat(dest, C128Table[96]); /* FNC3 */
				values[1] = 96;
				concat(dest, C128Table[99]); /* Code C */
				values[2] = 99;
				bar_characters += 2;
				current_set = 'C';
				break;
		}
	} else {
		/* Normal mode */
		switch(set[0]) {
			case 'A': /* Start A */
				concat(dest, C128Table[103]);
				values[0] = 103;
				current_set = 'A';
				break;
			case 'B': /* Start B */
				concat(dest, C128Table[104]);
				values[0] = 104;
				current_set = 'B';
				break;
			case 'C': /* Start C */
				concat(dest, C128Table[105]);
				values[0] = 105;
				current_set = 'C';
				break;
		}
	}
	bar_characters++;
	last_set = set[0];

	if(fset[0] == 'F') {
		switch(current_set) {
			case 'A':
				concat(dest, C128Table[101]);
				concat(dest, C128Table[101]);
				values[bar_characters] = 101;
				values[bar_characters + 1] = 101;
				break;
			case 'B':
				concat(dest, C128Table[100]);
				concat(dest, C128Table[100]);
				values[bar_characters] = 100;
				values[bar_characters + 1] = 100;
				break;
		}
		bar_characters += 2;
		f_state = 1;
	}

	/* Encode the data */
	read = 0;
	do {

		if((read != 0) && (set[read] != current_set))
		{ /* Latch different code set */
			switch(set[read])
			{
				case 'A': concat(dest, C128Table[101]);
					values[bar_characters] = 101;
					bar_characters++;
					current_set = 'A';
					break;
				case 'B': concat(dest, C128Table[100]);
					values[bar_characters] = 100;
					bar_characters++;
					current_set = 'B';
					break;
				case 'C': concat(dest, C128Table[99]);
					values[bar_characters] = 99;
					bar_characters++;
					current_set = 'C';
					break;
			}
		}

		if(read != 0) {
			if((fset[read] == 'F') && (f_state == 0)) {
				/* Latch beginning of extended mode */
				switch(current_set) {
					case 'A':
						concat(dest, C128Table[101]);
						concat(dest, C128Table[101]);
						values[bar_characters] = 101;
						values[bar_characters + 1] = 101;
						break;
					case 'B':
						concat(dest, C128Table[100]);
						concat(dest, C128Table[100]);
						values[bar_characters] = 100;
						values[bar_characters + 1] = 100;
						break;
				}
				bar_characters += 2;
				f_state = 1;
			}
			if((fset[read] == ' ') && (f_state == 1)) {
				/* Latch end of extended mode */
				switch(current_set) {
					case 'A':
						concat(dest, C128Table[101]);
						concat(dest, C128Table[101]);
						values[bar_characters] = 101;
						values[bar_characters + 1] = 101;
						break;
					case 'B':
						concat(dest, C128Table[100]);
						concat(dest, C128Table[100]);
						values[bar_characters] = 100;
						values[bar_characters + 1] = 100;
						break;
				}
				bar_characters += 2;
				f_state = 0;
			}
		}

		if((fset[read] == 'f') || (fset[read] == 'n')) {
			/* Shift to or from extended mode */
			switch(current_set) {
				case 'A':
					concat(dest, C128Table[101]); /* FNC 4 */
					values[bar_characters] = 101;
					break;
				case 'B':
					concat(dest, C128Table[100]); /* FNC 4 */
					values[bar_characters] = 100;
					break;
			}
			bar_characters++;
		}

		if((set[read] == 'a') || (set[read] == 'b')) {
			/* Insert shift character */
			concat(dest, C128Table[98]);
			values[bar_characters] = 98;
			bar_characters++;
		}

		switch(set[read])
		{ /* Encode data characters */
			case 'a':
			case 'A': c128_set_a(source[read], dest, values, &bar_characters);
				read++;
				break;
			case 'b':
			case 'B': c128_set_b(source[read], dest, values, &bar_characters);
				read++;
				break;
			case 'C': c128_set_c(source[read], source[read + 1], dest, values, &bar_characters);
				read += 2;
				break;
		}

	} while (read < sourcelen);

	/* check digit calculation */
	total_sum = 0;
	/*for(i = 0; i < bar_characters; i++) {
		printf("%d\n", values[i]);
	}*/

	for (int i = 0; i < bar_characters; i++) {
		if(i > 0)
			values[i] *= i;
		total_sum += values[i];
	}
	concat(dest, C128Table[total_sum % 103]);

	/* Stop character */
	concat(dest, C128Table[106]);
	expand(symbol, dest);
	return error_number;
}
Beispiel #23
0
void
look3(Text *t, uint q0, uint q1, int external)
{
	int n, c, f, expanded;
	Text *ct;
	Expand e;
	Rune *r;
	uint p;
	Plumbmsg *m;
	Runestr dir;
	char buf[32];

	ct = seltext;
	if(ct == nil)
		seltext = t;
	expanded = expand(t, q0, q1, &e);
	if(!external && t->w!=nil && t->w->nopen[QWevent]>0){
		/* send alphanumeric expansion to external client */
		if(expanded == FALSE)
			return;
		f = 0;
		if((e.u.at!=nil && t->w!=nil) || (e.nname>0 && lookfile(e.name, e.nname)!=nil))
			f = 1;		/* acme can do it without loading a file */
		if(q0!=e.q0 || q1!=e.q1)
			f |= 2;	/* second (post-expand) message follows */
		if(e.nname)
			f |= 4;	/* it's a file name */
		c = 'l';
		if(t->what == Body)
			c = 'L';
		n = q1-q0;
		if(n <= EVENTSIZE){
			r = runemalloc(n);
			bufread(&t->file->b, q0, r, n);
			winevent(t->w, "%c%d %d %d %d %.*S\n", c, q0, q1, f, n, n, r);
			free(r);
		}else
			winevent(t->w, "%c%d %d %d 0 \n", c, q0, q1, f, n);
		if(q0==e.q0 && q1==e.q1)
			return;
		if(e.nname){
			n = e.nname;
			if(e.a1 > e.a0)
				n += 1+(e.a1-e.a0);
			r = runemalloc(n);
			runemove(r, e.name, e.nname);
			if(e.a1 > e.a0){
				r[e.nname] = ':';
				bufread(&e.u.at->file->b, e.a0, r+e.nname+1, e.a1-e.a0);
			}
		}else{
			n = e.q1 - e.q0;
			r = runemalloc(n);
			bufread(&t->file->b, e.q0, r, n);
		}
		f &= ~2;
		if(n <= EVENTSIZE)
			winevent(t->w, "%c%d %d %d %d %.*S\n", c, e.q0, e.q1, f, n, n, r);
		else
			winevent(t->w, "%c%d %d %d 0 \n", c, e.q0, e.q1, f, n);
		free(r);
		goto Return;
	}
	if(plumbsendfid != nil){
		/* send whitespace-delimited word to plumber */
		m = emalloc(sizeof(Plumbmsg));
		m->src = estrdup("acme");
		m->dst = nil;
		dir = dirname(t, nil, 0);
		if(dir.nr==1 && dir.r[0]=='.'){	/* sigh */
			free(dir.r);
			dir.r = nil;
			dir.nr = 0;
		}
		if(dir.nr == 0)
			m->wdir = estrdup(wdir);
		else
			m->wdir = runetobyte(dir.r, dir.nr);
		free(dir.r);
		m->type = estrdup("text");
		m->attr = nil;
		buf[0] = '\0';
		if(q1 == q0){
			if(t->q1>t->q0 && t->q0<=q0 && q0<=t->q1){
				q0 = t->q0;
				q1 = t->q1;
			}else{
				p = q0;
				while(q0>0 && (c=tgetc(t, q0-1))!=' ' && c!='\t' && c!='\n')
					q0--;
				while(q1<t->file->b.nc && (c=tgetc(t, q1))!=' ' && c!='\t' && c!='\n')
					q1++;
				if(q1 == q0){
					plumbfree(m);
					goto Return;
				}
				sprint(buf, "click=%d", p-q0);
				m->attr = plumbunpackattr(buf);
			}
		}
		r = runemalloc(q1-q0);
		bufread(&t->file->b, q0, r, q1-q0);
		m->data = runetobyte(r, q1-q0);
		m->ndata = strlen(m->data);
		free(r);
		if(m->ndata<messagesize-1024 && plumbsendtofid(plumbsendfid, m) >= 0){
			plumbfree(m);
			goto Return;
		}
		plumbfree(m);
		/* plumber failed to match; fall through */
	}

	/* interpret alphanumeric string ourselves */
	if(expanded == FALSE)
		return;
	if(e.name || e.u.at)
		openfile(t, &e);
	else{
		if(t->w == nil)
			return;
		ct = &t->w->body;
		if(t->w != ct->w)
			winlock(ct->w, 'M');
		if(t == ct)
			textsetselect(ct, e.q1, e.q1);
		n = e.q1 - e.q0;
		r = runemalloc(n);
		bufread(&t->file->b, e.q0, r, n);
		if(search(ct, r, n) && e.jump)
			moveto(mousectl, addpt(frptofchar(&ct->fr, ct->fr.p0), Pt(4, ct->fr.font->height-4)));
		if(t->w != ct->w)
			winunlock(ct->w);
		free(r);
	}

   Return:
	free(e.name);
	free(e.bname);
}
Beispiel #24
0
int ean_128(struct zint_symbol *symbol, const uint8_t source[], int length)
{ /* Handle EAN-128 (Now known as GS1-128) */
	int values[170], bar_characters, read, total_sum;
	int error_number, indexchaine, indexliste;
	char set[170], mode, last_set;
	float glyph_count;
	char dest[1000];
	int separator_row, linkage_flag, c_count;
        char reduced[length + 1];
	error_number = 0;
	strcpy(dest, "");
	linkage_flag = 0;

	bar_characters = 0;
	separator_row = 0;

	memset(values, 0, sizeof(values));
	memset(set, ' ', sizeof(set));

	if(length > 160) {
		/* This only blocks rediculously long input - the actual length of the
		resulting barcode depends on the type of data, so this is trapped later */
		strcpy(symbol->errtxt, "Input too long");
		return ZERROR_TOO_LONG;
	}

	for (int i = 0; i < length; i++) {
		if(source[i] == '\0') {
			/* Null characters not allowed! */
			strcpy(symbol->errtxt, "NULL character in input data");
			return ZERROR_INVALID_DATA;
		}
	}

	/* if part of a composite symbol make room for the separator pattern */
	if(symbol->symbology == BARCODE_EAN128_CC) {
		separator_row = symbol->rows;
		symbol->row_height[symbol->rows] = 1;
		symbol->rows += 1;
	}

	if(symbol->input_mode != GS1_MODE) {
		/* GS1 data has not been checked yet */
		error_number = gs1_verify(symbol, source, length, reduced);
		if(error_number != 0) { return error_number; }
	}

	/* Decide on mode using same system as PDF417 and rules of ISO 15417 Annex E */
	indexliste = 0;
	indexchaine = 0;

	mode = parunmodd(reduced[indexchaine]);
	if(reduced[indexchaine] == '[') {
		mode = ABORC;
	}

	memset(list[0], 0, 170 * sizeof(list[0][0]));

	do {
		list[1][indexliste] = mode;
		while ((list[1][indexliste] == mode) && (indexchaine < strlen(reduced))) {
			list[0][indexliste]++;
			indexchaine++;
			mode = parunmodd(reduced[indexchaine]);
			if(reduced[indexchaine] == '[') { mode = ABORC; }
		}
		indexliste++;
	} while (indexchaine < strlen(reduced));

	dxsmooth(&indexliste);

	/* Put set data into set[] */
	read = 0;
	for(int i = 0; i < indexliste; i++) {
		for(int j = 0; j < list[0][i]; j++) {
			switch(list[1][i]) {
			case SHIFTA:
				set[read] = 'a';
				break;
			case LATCHA:
				set[read] = 'A';
				break;
			case SHIFTB:
				set[read] = 'b';
				break;
			case LATCHB:
				set[read] = 'B';
				break;
			case LATCHC:
				set[read] = 'C';
				break;
			}
			read++;
		}
	}

	/* Watch out for odd-length Mode C blocks */
	c_count = 0;
	for (int i = 0; i < read; i++) {
		if(set[i] == 'C') {
			if(reduced[i] == '[') {
				if(c_count & 1) {
					if((i - c_count) != 0) {
						set[i - c_count] = 'B';
					} else {
						set[i - 1] = 'B';
					}
				}
				c_count = 0;
			} else {
				c_count++;
			}
		} else {
			if(c_count & 1) {
				if((i - c_count) != 0) {
					set[i - c_count] = 'B';
				} else {
					set[i - 1] = 'B';
				}
			}
			c_count = 0;
		}
	}

	if (c_count & 1) {
		if (read - c_count != 0) {
			set[read - c_count] = 'B';
		} else {
			set[read - 1] = 'B';
		}
	}

	for (int i = 1; i < read - 1; i++) {
		if((set[i] == 'C') && ((set[i - 1] == 'B') && (set[i + 1] == 'B'))) {
			set[i] = 'B';
		}
	}

	/* Now we can calculate how long the barcode is going to be - and stop it from
	   being too long */
	last_set = ' ';
	glyph_count = 0.0;
	for (int i = 0; i < strlen(reduced); i++) {
		if((set[i] == 'a') || (set[i] == 'b')) {
			glyph_count = glyph_count + 1.0;
		}
		if(((set[i] == 'A') || (set[i] == 'B')) || (set[i] == 'C')) {
			if(set[i] != last_set) {
				last_set = set[i];
				glyph_count = glyph_count + 1.0;
			}
		}

		if((set[i] == 'C') && (reduced[i] != '[')) {
			glyph_count = glyph_count + 0.5;
		} else {
			glyph_count = glyph_count + 1.0;
		}
	}
	if(glyph_count > 80.0) {
		strcpy(symbol->errtxt, "Input too long");
		return ZERROR_TOO_LONG;
	}

	/* So now we know what start character to use - we can get on with it! */
	switch (set[0]) {
		case 'A': /* Start A */
			concat(dest, C128Table[103]);
			values[0] = 103;
			break;
		case 'B': /* Start B */
			concat(dest, C128Table[104]);
			values[0] = 104;
			break;
		case 'C': /* Start C */
			concat(dest, C128Table[105]);
			values[0] = 105;
			break;
	}
	bar_characters++;

	concat(dest, C128Table[102]);
	values[1] = 102;
	bar_characters++;

	/* Encode the data */
	read = 0;
	do {
		if((read != 0) && (set[read] != set[read - 1]))
		{ /* Latch different code set */
			switch(set[read]) {
			case 'A':
				concat(dest, C128Table[101]);
				values[bar_characters] = 101;
				bar_characters++;
				break;
			case 'B':
				concat(dest, C128Table[100]);
				values[bar_characters] = 100;
				bar_characters++;
				break;
			case 'C':
				concat(dest, C128Table[99]);
				values[bar_characters] = 99;
				bar_characters++;
				break;
			}
		}

		if((set[read] == 'a') || (set[read] == 'b')) {
			/* Insert shift character */
			concat(dest, C128Table[98]);
			values[bar_characters] = 98;
			bar_characters++;
		}

		if(reduced[read] != '[') {
			/* Encode data characters */
			switch(set[read]) {
				case 'A':
				case 'a':
					c128_set_a(reduced[read], dest, values, &bar_characters);
					read++;
					break;
				case 'B':
				case 'b':
					c128_set_b(reduced[read], dest, values, &bar_characters);
					read++;
					break;
				case 'C':
					c128_set_c(reduced[read], reduced[read + 1], dest, values, &bar_characters);
					read += 2;
					break;
			}
		} else {
			concat(dest, C128Table[102]);
			values[bar_characters] = 102;
			bar_characters++;
			read++;
		}
	} while (read < strlen(reduced));

	/* "...note that the linkage flag is an extra code set character between
	   the last data character and the Symbol Check Character"
	   (GS1 Specification) */

	/* Linkage flags in GS1-128 are determined by ISO/IEC 24723 section 7.4 */

	switch(symbol->option_1) {
		case 1:
		case 2:
			/* CC-A or CC-B 2D component */
			switch(set[strlen(reduced) - 1]) {
				case 'A': linkage_flag = 100; break;
				case 'B': linkage_flag = 99; break;
				case 'C': linkage_flag = 101; break;
			}
			break;
		case 3:
			/* CC-C 2D component */
			switch(set[strlen(reduced) - 1]) {
				case 'A': linkage_flag = 99; break;
				case 'B': linkage_flag = 101; break;
				case 'C': linkage_flag = 100; break;
			}
			break;
	}

	if(linkage_flag != 0) {
		concat(dest, C128Table[linkage_flag]);
		values[bar_characters] = linkage_flag;
		bar_characters++;
	}

	/* check digit calculation */
	total_sum = 0;
	for(int i = 0; i < bar_characters; i++) {
		if(i > 0) {
			values[i] *= i;
		}
		total_sum += values[i];
	}
	concat(dest, C128Table[total_sum%103]);
	values[bar_characters] = total_sum % 103;
	bar_characters++;

	/* Stop character */
	concat(dest, C128Table[106]);
	values[bar_characters] = 106;
	bar_characters++;
	expand(symbol, dest);

	/* Add the separator pattern for composite symbols */
	if (symbol->symbology == BARCODE_EAN128_CC) {
		for (int i = 0; i < symbol->width; i++) {
			if (!(module_is_set(symbol, separator_row + 1, i))) {
				set_module(symbol, separator_row, i);
			}
		}
	}

	for(int i = 0; i < length; i++) {
		if((source[i] != '[') && (source[i] != ']')) {
			symbol->text[i] = source[i];
		}
		if(source[i] == '[') {
			symbol->text[i] = '(';
		}
		if(source[i] == ']') {
			symbol->text[i] = ')';
		}
	}

	return error_number;
}
Beispiel #25
0
void Tmpl::expand(bool bExt)
{
    for (unsigned i = 0; i < t.length(); i++){
        QChar c = t[(int)i];
        if (c == '\\'){
            if (i < t.length())
                res += t[(int)(++i)];
            continue;
        }
        if (c == '&'){
            QString var;
            for (i++; i < t.length(); i++){
                c = t[(int)i];
                if (c == ';') break;
                var += c;
            }
            if (var == "MyUin"){
                res += QString::number(pClient->owner->Uin);
                continue;
            }
            if (var == "MyAlias"){
                CUser owner(pClient->owner);
                res += owner.name(false);
                continue;
            }
            if (var == "Uin"){
                res += (m_uin >= UIN_SPECIAL) ? QString("") : QString::number(m_uin);
                continue;
            }
            if (var == "Alias"){
                CUser u(m_uin);
                res +=  u.name(false);
                continue;
            }
            string s;
            if (!var.isEmpty()) s = var.local8Bit();
            log(L_WARN, "Unknown substitute <%s>", s.c_str());
            continue;
        }
        if (bExt && (c == '`')){
            QString prg;
            for (i++; i < t.length(); i++){
                c = t[(int)i];
                if (c == '`') break;
                prg += c;
            }
            QString save_t = t.mid(i+1);
            QString save_res = res;
            t = prg;
            res = "";
            expand(false);
            prg = res;
            t = save_t;
            res = save_res;
            if (exec == NULL){
                exec = new Exec(this);
                connect(exec, SIGNAL(ready(int, const char*)), this, SLOT(execReady(int, const char*)));
            }
            exec->execute(prg.local8Bit(), NULL);
            return;
        }
Beispiel #26
0
int
main(int argc, char *argv[])
{
	char *p;
	struct acct ab;
	struct stat sb;
	FILE *fp;
	off_t size = 0;
	time_t t;
	int ch;
	const char *acctfile;
	int flags = 0;

	acctfile = _PATH_ACCT;
	while ((ch = getopt(argc, argv, "f:usecSE")) != -1)
		switch((char)ch) {
		case 'f':
			acctfile = optarg;
			break;

		case 'u': 
			flags |= AC_UTIME; /* user time */
			break;
		case 's':
			flags |= AC_STIME; /* system time */
			break;
		case 'e':
			flags |= AC_ETIME; /* elapsed time */
			break;
		case 'c':
                        flags |= AC_CTIME; /* user + system time */
			break;

		case 'S':
                        flags |= AC_BTIME; /* starting time */
			break;
		case 'E':
			/* exit time (starting time + elapsed time )*/
                        flags |= AC_FTIME; 
			break;

		case '?':
		default:
			usage();
		}

	/* default user + system time and starting time */
	if (!flags) {
	    flags = AC_CTIME | AC_BTIME;
	}

	argc -= optind;
	argv += optind;

	if (strcmp(acctfile, "-") == 0)
		fp = stdin;
	else {
		/* Open the file. */
		if ((fp = fopen(acctfile, "r")) == NULL ||
		    fstat(fileno(fp), &sb))
			err(1, "could not open %s", acctfile);

		/*
		 * Round off to integral number of accounting records,
		 * probably not necessary, but it doesn't hurt.
		 */
		size = sb.st_size - sb.st_size % sizeof(struct acct);

		/* Check if any records to display. */
		if ((unsigned)size < sizeof(struct acct))
			exit(0);
	}

	do {
		int rv;

		if (fp != stdin) {
			size -= sizeof(struct acct);
			if (fseeko(fp, size, SEEK_SET) == -1)
				err(1, "seek %s failed", acctfile);
		}

		if ((rv = fread(&ab, sizeof(struct acct), 1, fp)) != 1) {
			if (feof(fp))
				break;
			else
				err(1, "read %s returned %d", acctfile, rv);
		}

		if (ab.ac_comm[0] == '\0') {
			ab.ac_comm[0] = '?';
			ab.ac_comm[1] = '\0';
		} else
			for (p = &ab.ac_comm[0];
			    p < &ab.ac_comm[AC_COMM_LEN] && *p; ++p)
				if (!isprint(*p))
					*p = '?';
		if (*argv && !requested(argv, &ab))
			continue;

		(void)printf("%-*.*s %-7s %-*s %-*s",
			     AC_COMM_LEN, AC_COMM_LEN, ab.ac_comm,
			     flagbits(ab.ac_flag),
			     UT_NAMESIZE, user_from_uid(ab.ac_uid, 0),
			     UT_LINESIZE, getdev(ab.ac_tty));
		
		
		/* user + system time */
		if (flags & AC_CTIME) {
			(void)printf(" %6.2f secs", 
				     (expand(ab.ac_utime) + 
				      expand(ab.ac_stime))/AC_HZ);
		}
		
		/* usr time */
		if (flags & AC_UTIME) {
			(void)printf(" %6.2f us", expand(ab.ac_utime)/AC_HZ);
		}
		
		/* system time */
		if (flags & AC_STIME) {
			(void)printf(" %6.2f sy", expand(ab.ac_stime)/AC_HZ);
		}
		
		/* elapsed time */
		if (flags & AC_ETIME) {
			(void)printf(" %8.2f es", expand(ab.ac_etime)/AC_HZ);
		}
		
		/* starting time */
		if (flags & AC_BTIME) {
			(void)printf(" %.16s", ctime(&ab.ac_btime));
		}
		
		/* exit time (starting time + elapsed time )*/
		if (flags & AC_FTIME) {
			t = ab.ac_btime;
			t += (time_t)(expand(ab.ac_etime)/AC_HZ);
			(void)printf(" %.16s", ctime(&t));
		}
		printf("\n");

	} while (size > 0);
	exit(0);
}
Beispiel #27
0
/*
 * Set up editing on the given file name.
 * If the first character of name is %, we are considered to be
 * editing the file, otherwise we are reading our mail which has
 * signficance for mbox and so forth.
 *
 * If the -e option is being passed to mail, this function has a
 * tri-state return code: -1 on error, 0 on no mail, 1 if there is
 * mail.
 */
int
setfile(char *name)
{
    FILE *ibuf;
    int checkmode, i, fd;
    struct stat stb;
    char isedit = *name != '%' || getuserid(myname) != getuid();
    char *who = name[1] ? name + 1 : myname;
    char tempname[PATHSIZE];
    static int shudclob;

    checkmode = value("checkmode") != NULL;
    if ((name = expand(name)) == NULL)
        return (-1);

    if ((ibuf = Fopen(name, "r")) == NULL) {
        if (!isedit && errno == ENOENT)
            goto nomail;
        warn("%s", name);
        return (-1);
    }

    if (fstat(fileno(ibuf), &stb) < 0) {
        warn("fstat");
        (void)Fclose(ibuf);
        return (-1);
    }

    if (S_ISDIR(stb.st_mode) || !S_ISREG(stb.st_mode)) {
        (void)Fclose(ibuf);
        errno = S_ISDIR(stb.st_mode) ? EISDIR : EINVAL;
        warn("%s", name);
        return (-1);
    }

    /*
     * Looks like all will be well.  We must now relinquish our
     * hold on the current set of stuff.  Must hold signals
     * while we are reading the new file, else we will ruin
     * the message[] data structure.
     */

    holdsigs();
    if (shudclob)
        quit();

    /*
     * Copy the messages into /tmp
     * and set pointers.
     */

    readonly = 0;
    if ((i = open(name, 1)) < 0)
        readonly++;
    else
        (void)close(i);
    if (shudclob) {
        (void)fclose(itf);
        (void)fclose(otf);
    }
    shudclob = 1;
    edit = isedit;
    strlcpy(prevfile, mailname, sizeof(prevfile));
    if (name != mailname)
        strlcpy(mailname, name, sizeof(mailname));
    mailsize = fsize(ibuf);
    (void)snprintf(tempname, sizeof(tempname),
                   "%s/mail.RxXXXXXXXXXX", tmpdir);
    if ((fd = mkstemp(tempname)) == -1 || (otf = fdopen(fd, "w")) == NULL)
        err(1, "%s", tempname);
    (void)fcntl(fileno(otf), F_SETFD, 1);
    if ((itf = fopen(tempname, "r")) == NULL)
        err(1, "%s", tempname);
    (void)fcntl(fileno(itf), F_SETFD, 1);
    (void)rm(tempname);
    setptr(ibuf, 0);
    setmsize(msgCount);
    /*
     * New mail may have arrived while we were reading
     * the mail file, so reset mailsize to be where
     * we really are in the file...
     */
    mailsize = ftello(ibuf);
    (void)Fclose(ibuf);
    relsesigs();
    sawcom = 0;

    if ((checkmode || !edit) && msgCount == 0) {
nomail:
        if (!checkmode) {
            fprintf(stderr, "No mail for %s\n", who);
            return (-1);
        } else
            return (0);
    }
    return (checkmode ? 1 : 0);
}
void GxsChannelPostItem::toggle()
{
	expand(ui->expandFrame->isHidden());
}
Beispiel #29
0
void expandAndAppend(char **currentLine, char c)
{
    expand(currentLine);
    append(currentLine, c);
}
void ByteArrayOutputStream::write(int32_t b) {
    if (mCount == mBuffer->size()) {
        expand(1);
    }
    mBuffer->set(mCount++, (uint8_t) b);
}