Beispiel #1
0
static packet_type rle_packet_type(const uint8_t *row, const uint16_t pos,
    const uint16_t width, const uint16_t bpp)
{
    if (pos == width - 1) return RAW; /* one pixel */
    if (SAME(pos,pos+1)) /* dupe pixel */
    {
        if (bpp > 1) return RLE; /* inefficient for bpp=1 */

        /* three repeats makes the bpp=1 case efficient enough */
        if ((pos < width - 2) && SAME(pos+1,pos+2)) return RLE;
    }
    return RAW;
}
Beispiel #2
0
/* ---------------------------------------------------------------------------
 * Find the length of the current RLE packet.  This is a helper function
 * called from tga_write_row_RLE().
 */
static uint8_t rle_packet_len(const uint8_t *row, const uint16_t pos,
    const uint16_t width, const uint16_t bpp, const packet_type type)
{
    uint8_t len = 2;

    if (pos == width - 1) return 1;
    if (pos == width - 2) return 2;

    if (type == RLE)
    {
        while (pos + len < width)
        {
            if (SAME(pos, pos+len))
                len++;
            else
                return len;

            if (len == 128) return 128;
        }
    }
    else /* type == RAW */
    {
        while (pos + len < width)
        {
            if (rle_packet_type(row, pos+len, width, bpp) == RAW)
                len++;
            else
                return len;
            if (len == 128) return 128;
        }
    }
    return len; /* hit end of row (width) */
}
Beispiel #3
0
THelp :: THotkeyType  	THelp :: IsHotkey  ( HWND 	/* hwnd */,
					     uint	message,
					     WPARAM	wparam,
					     LPARAM	/* lparam */ )
   {
	register int		i ;
	uint			KeyCode ;
	TKeyModifiers		Modifiers ;
	THotkeyType		Type ;
	unsigned int		control, alt, shift ;



	if  ( message  !=   WM_KEYDOWN  &&  message  !=  WM_CHAR )
		return ( Unknown ) ;


	for  ( i = 0 ; i < MAX_HOTKEYS ; i ++ )
	   {
		if  ( ! Hotkeys [i]. KeyCode )
			continue ;

		
		KeyCode		=  Hotkeys [i]. KeyCode ;
		Modifiers	=  Hotkeys [i]. Modifiers ;
		Type		=  Hotkeys [i]. Type ;
		
		control 	=  GetAsyncKeyState ( VK_CONTROL )  &  0x8000 ;
		alt		=  GetAsyncKeyState ( VK_MENU    )  &  0x8000 ;
		shift		=  GetAsyncKeyState ( VK_SHIFT   )  &  0x8000 ;

		if  ( message  !=  WM_KEYDOWN )
			return  ( Unknown ) ;

		if  ( KeyCode  !=  wparam )
			return ( Unknown ) ;

		if  ( SAME ( Modifiers & Control, control )  &&
		      SAME ( Modifiers & Alt    , alt     )  &&
		      SAME ( Modifiers & Shift  , shift ) )
			return  ( Type ) ;
	     }


	return ( Unknown ) ;
     }
Beispiel #4
0
int check(uint32_t *a, uint32_t *b)
{
    uint32_t tmp[6];
    int i;
    memcpy(tmp, a, sizeof(uint32_t) * 6);
    for(i = 0;i < 5; i++)
    {
        rotate_one(tmp, 6);
        if(SAME(tmp, b)) return 1;
    }
    
    memcpy(tmp, a, sizeof(uint32_t) * 6);
    for(i = 0;i < 5; i++)
    {
        rerotate_one(tmp, 6);
        if(SAME(tmp, b)) return 1;
    }
    return 0;
}
Beispiel #5
0
static int
max_requests_needing_pwheel_mounted(char *pwheel_name)
{
	PSTATUS *		pps;
	RSTATUS *		prs;
	int			max	= 0;
	int			i;


	/*
	 * For each printer that doesn't have this print-wheel mounted,
	 * count the number of requests needing this print-wheel and
	 * assigned to the printer. Find the maximum across all such
	 * printers. Sorry, the code actually has a different loop
	 * (it steps through the requests) but the description of what
	 * happens below is easier to understand as given. (Looping
	 * through the printers would result in #printers x #requests
	 * steps, whereas this entails #requests steps.)
	 */
	for (i = 0; PStatus != NULL && PStatus[i] != NULL; i++)
		PStatus[i]->nrequests = 0;

	for (prs = Request_List; prs != NULL; prs = prs->next)
		if ((prs->pwheel_name != NULL) &&
		    (STREQU(prs->pwheel_name, pwheel_name)) &&
		    ((pps = prs->printer) != NULL) && pps->printer->daisy &&
		    (!SAME(pps->pwheel_name, pwheel_name)))
			if (++pps->nrequests >= max)
				max = pps->nrequests;

	if (NewRequest)
		if (
			((pps = NewRequest->printer) != NULL)
		     && pps->printer->daisy
		     && !SAME(pps->pwheel_name, pwheel_name)
		)
			if (++pps->nrequests >= max)
				max = pps->nrequests;
	return (max);
}
Beispiel #6
0
static const char *
begin_word(const char *text, const char *begin)
{
	gunichar ch = 0;
	while (text > begin && (!*text || g_unichar_isspace(g_utf8_get_char(text))))
		text = g_utf8_find_prev_char(begin, text);
	ch = g_utf8_get_char(text);
	while ((text = g_utf8_find_prev_char(begin, text)) >= begin) {
		gunichar cur = g_utf8_get_char(text);
		if (!SAME(ch, cur))
			break;
	}

	return (text ? g_utf8_find_next_char(text, NULL) : begin);
}
Beispiel #7
0
static GList *
split_string(const char *string)
{
	GList *ret = NULL;
	const char *start, *end;

	start = end = string;
	while (*start) {
		while (*end && SAME(*start, *end)) {
			end++;
		}
		ret = g_list_append(ret, g_strndup(start, end - start));
		start = end;
	}

	return ret;
}
Beispiel #8
0
static const char *
next_begin_word(const char *text, const char *end)
{
	gunichar ch = 0;

	while (text && text < end && g_unichar_isspace(g_utf8_get_char(text)))
		text = g_utf8_find_next_char(text, end);

	if (text) {
		ch = g_utf8_get_char(text);
		while ((text = g_utf8_find_next_char(text, end)) != NULL && text <= end) {
			gunichar cur = g_utf8_get_char(text);
			if (!SAME(ch, cur))
				break;
		}
	}
	return (text ? text : end);
}
Beispiel #9
0
bool identical_messages_(const GPB::Message* m1, const GPB::Message* m2, double tol) {
    const GPB::Descriptor* d1 = m1->GetDescriptor();
    const GPB::Descriptor* d2 = m2->GetDescriptor();

    /* first of all, check if this is the same message type */
    if (d1 != d2) {
        return false;
    }

    const GPB::Reflection* ref = m2->GetReflection();

    /* iterate field descriptors */
    int nf = d1->field_count();
    for (int i = 0; i < nf; i++) {
        const GPB::FieldDescriptor* field_desc = d1->field(i);

        if (field_desc->is_repeated()) {

            /* test if the size differs */
            int fs = ref->FieldSize(*m1, field_desc);
            if (fs != ref->FieldSize(*m2, field_desc)) return false;

            /* test all items */
            switch (field_desc->type()) {
                case TYPE_INT32:
                case TYPE_SINT32:
                case TYPE_SFIXED32: {
                    for (int j = 0; j < fs; j++) {
                        if (ref->GetRepeatedInt32(*m1, field_desc, j) !=
                            ref->GetRepeatedInt32(*m2, field_desc, j))
                            return false;
                    }
                    break;
                }
                case TYPE_INT64:
                case TYPE_SINT64:
                case TYPE_SFIXED64: {
                    for (int j = 0; j < fs; j++) {
                        if (ref->GetRepeatedInt64(*m1, field_desc, j) !=
                            ref->GetRepeatedInt64(*m2, field_desc, j))
                            return false;
                    }
                    break;
                }
                case TYPE_UINT32:
                case TYPE_FIXED32: {
                    for (int j = 0; j < fs; j++) {
                        if (ref->GetRepeatedUInt32(*m1, field_desc, j) !=
                            ref->GetRepeatedUInt32(*m2, field_desc, j))
                            return false;
                    }
                    break;
                }
                case TYPE_UINT64:
                case TYPE_FIXED64: {
                    for (int j = 0; j < fs; j++) {
                        if (ref->GetRepeatedUInt64(*m1, field_desc, j) !=
                            ref->GetRepeatedUInt64(*m2, field_desc, j))
                            return false;
                    }
                    break;
                }
                case TYPE_DOUBLE: {
                    for (int j = 0; j < fs; j++) {
                        if (!SAME(ref->GetRepeatedDouble(*m1, field_desc, j),
                                  ref->GetRepeatedDouble(*m2, field_desc, j), tol))
                            return false;
                    }
                    break;
                }
                case TYPE_FLOAT: {
                    for (int j = 0; j < fs; j++) {
                        if (!SAME(ref->GetRepeatedFloat(*m1, field_desc, j),
                                  ref->GetRepeatedFloat(*m2, field_desc, j), tol))
                            return false;
                    }
                    break;
                }
                case TYPE_BOOL: {
                    for (int j = 0; j < fs; j++) {
                        if (ref->GetRepeatedBool(*m1, field_desc, j) !=
                            ref->GetRepeatedBool(*m2, field_desc, j))
                            return false;
                    }
                    break;
                }
                case TYPE_STRING:
                case TYPE_BYTES: {
                    for (int j = 0; j < fs; j++) {
                        if (ref->GetRepeatedString(*m1, field_desc, j) !=
                            ref->GetRepeatedString(*m2, field_desc, j))
                            return false;
                    }
                    break;
                }
                case TYPE_ENUM: {
                    for (int j = 0; j < fs; j++) {
                        if (ref->GetRepeatedEnum(*m1, field_desc, j) !=
                            ref->GetRepeatedEnum(*m2, field_desc, j))
                            return false;
                    }
                    break;
                }
                case TYPE_MESSAGE:
                case TYPE_GROUP: {
                    for (int j = 0; j < fs; j++) {
                        const GPB::Message* mm1 = &ref->GetRepeatedMessage(*m1, field_desc, j);
                        const GPB::Message* mm2 = &ref->GetRepeatedMessage(*m2, field_desc, j);
                        if (!identical_messages_(mm1, mm2, tol)) {
                            return false;
                        }
                    }
                    break;
                }
                default:
                    Rcpp_error("unknown type");
            }

        } else {

            switch (field_desc->type()) {
                case TYPE_INT32:
                case TYPE_SINT32:
                case TYPE_SFIXED32: {
                    if (ref->GetInt32(*m1, field_desc) != ref->GetInt32(*m2, field_desc))
                        return false;
                    break;
                }
                case TYPE_INT64:
                case TYPE_SINT64:
                case TYPE_SFIXED64: {
                    if (ref->GetInt64(*m1, field_desc) != ref->GetInt64(*m2, field_desc))
                        return false;
                    break;
                }
                case TYPE_UINT32:
                case TYPE_FIXED32: {
                    if (ref->GetUInt32(*m1, field_desc) != ref->GetUInt32(*m2, field_desc))
                        return false;
                    break;
                }
                case TYPE_UINT64:
                case TYPE_FIXED64: {
                    if (ref->GetUInt64(*m1, field_desc) != ref->GetUInt64(*m2, field_desc))
                        return false;
                    break;
                }
                case TYPE_DOUBLE: {
                    if (ref->GetDouble(*m1, field_desc) != ref->GetDouble(*m2, field_desc))
                        return false;
                    break;
                }
                case TYPE_FLOAT: {
                    if (ref->GetFloat(*m1, field_desc) != ref->GetFloat(*m2, field_desc))
                        return false;
                    break;
                }
                case TYPE_BOOL: {
                    if (ref->GetBool(*m1, field_desc) != ref->GetBool(*m2, field_desc))
                        return false;
                    break;
                }
                case TYPE_STRING:
                case TYPE_BYTES: {
                    if (ref->GetString(*m1, field_desc) != ref->GetString(*m2, field_desc))
                        return false;
                    break;
                }
                case TYPE_ENUM: {
                    if (ref->GetEnum(*m1, field_desc) != ref->GetEnum(*m2, field_desc))
                        return false;
                    break;
                }
                case TYPE_MESSAGE:
                case TYPE_GROUP: {
                    const GPB::Message* mm1 = &ref->GetMessage(*m1, field_desc);
                    const GPB::Message* mm2 = &ref->GetMessage(*m2, field_desc);
                    if (!identical_messages_(mm1, mm2, tol)) {
                        return false;
                    }
                    break;
                }
                default:
                    Rcpp_error("unknown type");
            }
        }
    }
    /* finally */
    return true;
}
Beispiel #10
0
// ===================================================================
// NOTE: Your internal data structure may be different (& this print
// differently), depending on how you implement your internal member
// functions.  That's ok!
void BasicTests() {

  // make two matching list of integers, one using an unrolled list,
  // one using an STL list.  They should stay the "SAME" throughout
  // these tests.
  UnrolledLL<int> a;
  std::list<int> b;
  for (int i = 10; i < 30; ++i) {
    a.push_back(i);
    b.push_back(i);
  }  

  // iterate through the integers and print them out
  std::cout << "the integers from 10->29" << std::endl;
  a.print(std::cout);
  for (UnrolledLL<int>::iterator itr = a.begin(); itr != a.end(); itr++) {
    std::cout << " " << *itr;
  }
  std::cout << std::endl << std::endl;
  assert (SAME(a,b));

  // use the output operator to print the underlying representation
  std::cout << "initial" << std::endl;
  a.print(std::cout);
  std::cout << std::endl;

  // testing some basic functions in the class
  std::cout << "some editing with pop & push" << std::endl;
  assert (a.size() == 20);
  assert (a.front() == 10);
  assert (a.back() == 29);
  a.print(std::cout);
  std::list<int>::iterator i;
  std::cout<<std::endl;
  a.pop_front(); 
  b.pop_front();
  a.print(std::cout);
  //std::list<int>::iterator i;
  for(i=b.begin(); i!=b.end(); i++){
    std::cout << *i<<" ";
  }
  std::cout<<std::endl;
  assert (SAME(a,b));
  assert (a.size() == 19);
  assert (a.front() == 11);
  a.pop_back();
  b.pop_back();
  assert (a.size() == 18);
  assert (a.back() == 28);
  a.print(std::cout);
  std::cout << std::endl;
  assert (SAME(a,b));

  // more editing
  std::cout << "more editing with pop & push" << std::endl;
  a.pop_front();
  a.pop_front();
  a.pop_front();
  a.pop_front();
  a.pop_front();
  b.pop_front();
  b.pop_front();
  b.pop_front();
  b.pop_front();
  b.pop_front();
  a.print(std::cout);
  a.pop_back();
  b.pop_back();
  a.print(std::cout);
  assert (a.size() == 12);
  assert (a.front() == 16);
  assert (a.back() == 27);
  a.push_front(90);
  a.push_front(91);
  a.push_front(92);
  a.push_front(93);
  b.push_front(90);
  b.push_front(91);
  b.push_front(92);
  b.push_front(93);
  a.print(std::cout);
  std::cout << std::endl;
  assert (a.size() == 16);
  assert (a.front() == 93);
  assert (SAME(a,b));

  // erase the multiples of 3
  std::cout <<"erase the multiples of 3" << std::endl;
  UnrolledLL<int>::iterator a_iter = a.begin();
  while (a_iter != a.end()) {
    if (*a_iter % 3 == 0) {      
      a_iter = a.erase(a_iter);
      //a.print(std::cout);
    } else {
      a_iter++;
    }

  }

  std::list<int>::iterator b_iter = b.begin();
  while (b_iter != b.end()) {
    if (*b_iter % 3 == 0) {
      b_iter = b.erase(b_iter);
    } else {
      b_iter++;
    }
  }
  a.print(std::cout);
  std::cout << std::endl;
  assert (a.size() == 10);
  assert (SAME(a,b));

  // inserting elements
  std::cout << "do some inserts" << std::endl;
  // insert some stuff
  for (UnrolledLL<int>::iterator itr = a.begin(); itr != a.end(); itr++) {
    if (*itr == 92 || *itr == 16 || *itr == 19 || *itr == 26) {
      itr = a.insert(itr,77);
      //a.print(std::cout);
      itr++;
    } 
  }
  for (std::list<int>::iterator itr = b.begin(); itr != b.end(); itr++) {
    if (*itr == 92 || *itr == 16 || *itr == 19 || *itr == 26) {
      itr = b.insert(itr,77);
      itr++;
    } 
  }
  a.print(std::cout);
  std::cout << std::endl;
  assert (a.size() == 14);
  assert (SAME(a,b));
  
  // overflowing an insert
  std::cout << "insert that overflows the node" << std::endl;
  for (UnrolledLL<int>::iterator itr = a.begin(); itr != a.end(); itr++) {
    if (*itr == 17) {
      itr = a.insert(itr,88);
      itr++;
    } 
  }
  for (std::list<int>::iterator itr = b.begin(); itr != b.end(); itr++) {
    if (*itr == 17) {
      itr = b.insert(itr,88);
      itr++;
    } 
  }
  a.print(std::cout);
  std::cout << std::endl;
  assert (a.size() == 15);
  assert (SAME(a,b));

  // more erasing
  std::cout << "erasing that removes a node" << std::endl;
  a_iter = a.begin();
  while (a_iter != a.end()) {
    if (*a_iter == 77 || *a_iter == 16 || *a_iter == 88) {
      a_iter = a.erase(a_iter);
      a.print(std::cout);
    } else {
      a_iter++;
    }
  }
  b_iter = b.begin();
  while (b_iter != b.end()) {
    if (*b_iter == 77 || *b_iter == 16 || *b_iter == 88) {
      b_iter = b.erase(b_iter);
    } else {
      b_iter++;
    }
  }
  a.print(std::cout);
  std::cout << std::endl;
  assert (a.size() == 9);
  //std::cout << "here" << std::endl;

  assert (SAME(a,b));
  std::cout << "here6" << std::endl;

}
Beispiel #11
0
void
s_inquire_request_rank(char *m, MESG *md)
{
	char		*form;
	char		*dest;
	char		*pwheel;
	char		*user;
	char		*req_id;
	RSTATUS		*rp;
	RSTATUS		*found = NULL;
	int		found_rank = 0;
	short		prop;
	char		files[BUFSIZ];
	int 		i;

	(void) getmessage(m, S_INQUIRE_REQUEST_RANK, &prop, &form, &dest,
	    &req_id, &user, &pwheel);
	syslog(LOG_DEBUG, "s_inquire_request_rank(%d, %s, %s, %s, %s, %s)",
	    prop, (form ? form : "NULL"), (dest ? dest : "NULL"),
	    (req_id ? req_id : "NULL"), (user ? user : "******"),
	    (pwheel ? pwheel : "NULL"));

	for (i = 0; PStatus != NULL && PStatus[i] != NULL; i++)
		PStatus[i]->nrequests = 0;

	for (rp = Request_List; rp != NULL; rp = rp->next) {
		if (rp->printer && !(rp->request->outcome & RS_DONE))
			rp->printer->nrequests++;

		if (*form && !SAME(form, rp->request->form))
			continue;

		if (*dest && !STREQU(dest, rp->request->destination)) {
			if (!rp->printer)
				continue;
			if (!STREQU(dest, rp->printer->printer->name))
				continue;
		}

		if (*req_id && !STREQU(req_id, rp->secure->req_id))
			continue;

		if (*user && !bangequ(user, rp->secure->user))
			continue;

		if (*pwheel && !SAME(pwheel, rp->pwheel_name))
			continue;
		/*
		 * For Trusted Extensions, we need to check the sensitivity
		 * label of the connection and job before we return it to the
		 * client.
		 */
		if ((md->admin <= 0) && (is_system_labeled()) &&
		    (md->slabel != NULL) && (rp->secure->slabel != NULL) &&
		    (!STREQU(md->slabel, rp->secure->slabel)))
			continue;

		if (found) {
			GetRequestFiles(found->request, files, sizeof (files));
			mputm(md, R_INQUIRE_REQUEST_RANK,
			    MOKMORE,
			    found->secure->req_id,
			    found->request->user,
			    /* bgolden 091996, bug 1257405 */
			    found->secure->slabel,
			    found->secure->size,
			    found->secure->date,
			    found->request->outcome,
			    found->printer->printer->name,
			    (found->form? found->form->form->name : ""),
			    NB(found->pwheel_name),
			    found_rank,
			    files);
		}
		found = rp;
		found_rank = found->printer->nrequests;
	}

	if (found) {
		GetRequestFiles(found->request, files, sizeof (files));
		mputm(md, R_INQUIRE_REQUEST_RANK,
		    MOK,
		    found->secure->req_id,
		    found->request->user, /* bgolden 091996, bug 1257405 */
		    found->secure->slabel,
		    found->secure->size,
		    found->secure->date,
		    found->request->outcome,
		    found->printer->printer->name,
		    (found->form? found->form->form->name : ""),
		    NB(found->pwheel_name),
		    found_rank,
		    files);
	} else
		mputm(md, R_INQUIRE_REQUEST_RANK, MNOINFO, "", "", "", 0L, 0L,
		    0, "", "", "", 0, "");
}
opts_t parseargs(int *argc, char** argv[], int *isok)
{ opts_t opts={0};
  int iarg,iopt;
  unsigned char *hit=0;  // flags to indicate an argv was used in option processing
  TRY(argc && argv && isok);
  *isok=0;
  TRY(hit=(unsigned char*)alloca(*argc));
  memset(hit,0,*argc);
  ARGV=(char**)*argv;
  ARGC=*argc;
  for(iarg=1;iarg<*argc;++iarg)
  { for(iopt=0;iopt<countof(SPEC);++iopt)
    { if( SAME(argv[0][iarg],SPEC[iopt].shortname)
        ||SAME(argv[0][iarg],SPEC[iopt].longname ))
      { CALLBACK(iopt,opts);
        hit[iarg]=1;
        if(!SPEC[iopt].is_flag)
        { if(!VALIDATE(iopt,argv[0][iarg+1]))
          { LOG("\tArgument validation error.\n\tOption \"%s\" got \"%s\".\n",argv[0][iarg],argv[0][iarg+1]);
            goto Error;
          }
          if(!PARSE(iopt,opts,argv[0][iarg+1]))
          { LOG("\tArgument parse error.\n\tOption \"%s\" got \"%s\".\n",argv[0][iarg],argv[0][iarg+1]);
            goto Error;
          }
          SPEC[iopt].state.is_found=1;
          iarg++; // consumes an argument
          hit[iarg]=1;
        }
      }
    }
  }
  // apply default value for missing arguments
  for(iopt=0;iopt<countof(SPEC);++iopt)
  { if(!SPEC[iopt].is_flag && !SPEC[iopt].state.is_found)
    { if(SPEC[iopt].def) // if a default exists...
      { if(!VALIDATE(iopt,SPEC[iopt].def))
        { LOG("\tDefault argument failed to validate.\n\tOption \"%s\" got \"%s\".\n",SPEC[iopt].shortname,SPEC[iopt].def);
          goto Error;
        }
        if(!PARSE(iopt,opts,SPEC[iopt].def))
        { LOG("\tDefault argument failed to parse.\n\tOption \"%s\" got \"%s\".\n",SPEC[iopt].shortname,SPEC[iopt].def);
          goto Error;
        }
      }
    }
  }
  // fixed place argument handling and sections
#undef CALLBACK
#undef VALIDATE
#undef PARSE  
#define CALLBACK(iopt,opts)      if(ARGS[iopt].callback) ARGS[iopt].callback(&opts)
#define VALIDATE(iopt,str)       (ARGS[iopt].validate==NULL || ARGS[iopt].validate(str))
#define PARSE(iopt,opts,str)     (ARGS[iopt].parse==NULL || ARGS[iopt].parse(&opts,str))
  for(iarg=1,iopt=0;(iarg<*argc)&&(iopt<countof(ARGS));++iarg)
  { if(hit[iarg]) continue;
    if(!VALIDATE(iopt,argv[0][iarg]))
    { LOG("\tPositional argument validation error.\n\tOption <%s> got \"%s\".\n",ARGS[iopt].name,argv[0][iarg]);
      goto Error;
    }
    if(!PARSE(iopt,opts,argv[0][iarg]))
    { LOG("\tPositional argument parse error.\n\tOption <%s> got \"%s\".\n",ARGS[iopt].name,argv[0][iarg]);
      goto Error;
    }
    ARGS[iopt++].state.is_found=1;
  }
  // The specified fixed place args must be found
  // Not too worried about extra args
  for(iopt=0;iopt<countof(ARGS);++iopt)
  { if(!ARGS[iopt].state.is_found)
    { LOG("\tMissing required positional argument <%s>.\n",ARGS[iopt].name);
      goto Error;
    }
  }
  *isok=1;
  return opts;
Error:
  if(isok) *isok=0;
  usage();
  return opts;
}
Beispiel #13
0
void
check_pwheel_alert(PWSTATUS *ppws, PWHEEL *ppw)
{
	short			trigger,
				fire_off_alert	= 0;
	int			requests_waiting;


	/*
	 * Call this routine whenever a request has been queued
	 * or dequeued for a print-wheel, and whenever the print-wheel
	 * changes. If a pointer to a new PWHEEL is passed, the
	 * PWSTATUS structure is updated with the changes. Use a
	 * second argument of 0 if no change.
	 *
	 * WARNING: It is valid to call this routine when adding
	 * a NEW print wheel (not just changing it). Thus the members
	 * of the structure "ppws->pwheel" may not be set.
	 * In this case, though, "ppw" MUST be set, and there can
	 * be NO alert active.
	 */

	if (ppw) {
		if ((trigger = ppw->alert.Q) <= 0)
			trigger = 1;
	} else
		trigger = ppws->trigger;

	if (Starting)
		goto Return;

#define	OALERT	ppws->pwheel->alert
#define NALERT	ppw->alert

	requests_waiting = max_requests_needing_pwheel_mounted(ppws->pwheel->name);

	/*
	 * Cancel an active alert if the number of requests queued
	 * has dropped below the threshold (or the threshold has been
	 * raised), or if the alert command or period has changed.
	 * In the latter case we'll reactive the alert later.
	 */
	if (ppws->alert->active)
		if (!requests_waiting || requests_waiting < trigger)
			cancel_alert (A_PWHEEL, ppws);

		else if (
			ppw
		     && (
				!SAME(NALERT.shcmd, OALERT.shcmd)
			     || NALERT.W != OALERT.W
			     || NALERT.Q != OALERT.Q
			)
		)
			cancel_alert (A_PWHEEL, ppws);

	/*
	 * If we still have the condition for an alert, we'll fire
	 * one off. It is possible the alert is still running, but
	 * that's okay. First, we may want to change the alert message;
	 * second, the "alert()" routine doesn't execute an alert
	 * if it is already running.
	 */
	if (trigger > 0 && requests_waiting >= trigger)
		if ((ppw && NALERT.shcmd) || OALERT.shcmd)
			fire_off_alert = 1;

#undef	OALERT
#undef	NALERT

Return:	if (ppw) {

		ppws->pwheel = ppw;
		ppws->trigger = trigger;
	}

	/*
	 * Have to do this after updating the changes.
	 */
	if (fire_off_alert)
		alert (A_PWHEEL, ppws);

	return;
}
Beispiel #14
0
void
check_form_alert(FSTATUS *pfs, _FORM *pf)
{
	short			trigger,
				fire_off_alert	= 0;

	int			requests_waiting;


	/*
	 * Call this routine whenever a requests has been queued
	 * or dequeued for a form, and whenever the form changes.
	 * If a pointer to a new _FORM is passed, the FSTATUS
	 * structure is updated with the changes. Use a second
	 * argument of 0 if no change.
	 *
	 * WARNING: It is valid to call this routine when adding
	 * a NEW form (not just changing it). Thus the members of
	 * the structure "pfs->form" may not be set.
	 * In this case, though, "pf" MUST be set, and there can
	 * be NO alert active.
	 */

	syslog(LOG_DEBUG, "check_form_alert:\n");
	if (pfs) 
		syslog(LOG_DEBUG, "check_form_alert: pfs->name <%s>\n",
			(pfs->form->name != NULL) ? pfs->form->name : "null");
	if (pf)
		syslog(LOG_DEBUG, "check_form_alert: pf->name <%s>\n",
			(pf->name != NULL) ? pf->name : "null");


	if (pf) {
		if ((trigger = pf->alert.Q) <= 0)
			trigger = 1;
	} else
		trigger = pfs->trigger;

	if (Starting)
		goto Return;

#define	OALERT	pfs->form->alert
#define NALERT	pf->alert

	requests_waiting = max_requests_needing_form_mounted(pfs);

	/*
	 * Cancel an active alert if the number of requests queued
	 * has dropped below the threshold (or the threshold has been
	 * raised), or if the alert command or period has changed.
	 * In the latter case we'll reactive the alert later.
	 */
	if (pfs->alert->active)
		if (!requests_waiting || requests_waiting < trigger)
			cancel_alert (A_FORM, pfs);

		else if (
			pf
		     && (
				!SAME(NALERT.shcmd, OALERT.shcmd)
			     || NALERT.W != OALERT.W
			     || NALERT.Q != OALERT.Q
			)
		)
			cancel_alert (A_FORM, pfs);

	/*
	 * If we still have the condition for an alert, we'll fire
	 * one off. It is possible the alert is still running, but
	 * that's okay. First, we may want to change the alert message;
	 * second, the "alert()" routine doesn't execute an alert
	 * if it is already running.
	 */
	if (trigger > 0 && requests_waiting >= trigger)
		if ((pf && NALERT.shcmd) || OALERT.shcmd)
			fire_off_alert = 1;

#undef	OALERT
#undef	NALERT

Return:	if (pf) {

		 pfs->form = pf; 

		pfs->trigger = trigger;
	}

	/*
	 * Have to do this after updating the changes.
	 */
	if (fire_off_alert)
		alert (A_FORM, pfs);

	return;
}
Beispiel #15
0
static Int
sameSidesArea(Area a, Area b)
{ int a_top, a_center, a_bottom, a_left, a_middle, a_right;
  int b_top, b_center, b_bottom, b_left, b_middle, b_right;
  register unsigned long mask;

  InitAreaA;
  InitAreaB;

  NormaliseArea(ax, ay, aw, ah);
  NormaliseArea(bx, by, bw, bh);

  a_top = ay;
  a_bottom = ay+ah-1;
  a_center = (a_top+a_bottom+1)/2;

  a_left = ax;
  a_right = ax+aw-1;
  a_middle = (a_left+a_right+1)/2;

  b_top = by;
  b_bottom = by+bh-1;
  b_center = (b_top+b_bottom+1)/2;

  b_left = bx;
  b_right = bx+bw-1;
  b_middle = (b_left+b_right+1)/2;

  mask = 0;

  SAME(a_top,    b_top,    mask, 01);
  SAME(a_top,    b_center, mask, 02);
  SAME(a_top,    b_bottom, mask, 04);
  SAME(a_center, b_top,    mask, 010);
  SAME(a_center, b_center, mask, 020);
  SAME(a_center, b_bottom, mask, 040);
  SAME(a_bottom, b_top,    mask, 0100);
  SAME(a_bottom, b_center, mask, 0200);
  SAME(a_bottom, b_bottom, mask, 0400);

  SAME(a_left,   b_left,   mask, 01000);
  SAME(a_left,   b_middle, mask, 02000);
  SAME(a_left,   b_right,  mask, 04000);
  SAME(a_middle, b_left,   mask, 010000);
  SAME(a_middle, b_middle, mask, 020000);
  SAME(a_middle, b_right,  mask, 040000);
  SAME(a_right,  b_left,   mask, 0100000);
  SAME(a_right,  b_middle, mask, 0200000);
  SAME(a_right,  b_right,  mask, 0400000);

  answer(toInt(mask));
}