コード例 #1
0
ファイル: optparse.c プロジェクト: surajpkn/flux-core
static void
optparse_option_print (optparse_t p, struct optparse_option *o, int columns)
{
    int n;
    char *equals = "";
    char *arginfo = "";
    char *s, *q;
    char info [81];
    char seg [81];
    char buf [4096];

    int descsiz;

    int left_pad = p->left_margin;
    int width = p->option_width;

    if (o->arginfo) {
        equals = "=";
        arginfo = (char *) o->arginfo;
    }

    if (isalnum (o->key)) {
        n = snprintf (info, sizeof (info), "%*s-%c, --%s%s%s",
                left_pad, "", o->key, o->name, equals, arginfo);
    }
    else {
        n = snprintf (info, sizeof (info), "%*s--%s%s%s",
                left_pad+4, "", o->name, equals, arginfo);
    }

    if ((n < 0) || (n > columns))
        snprintf(info + columns - 2, n + 1, "+");

    /*
     *  Copy "usage" string to buffer as we might modify below
     */
    q = buf;
    strncpy (buf, o->usage, sizeof (buf) - 1);

    descsiz = columns - width;
    s = get_next_segment (&q, descsiz, seg, sizeof (seg));

    /*
     *  Print first line of usage output. If the total length of
     *   of the usage message overflows the width we have allowed
     *   for it, then split the help message onto the next line.
     */
    if (n < width)
        (*p->log_fn) ("%-*s%s\n", width, info, s);
    else
        (*p->log_fn) ("\n%s\n%*s%s\n", info, width, "", s);

    /*  Get remaining usage lines (line-wrapped)
     */
    while ((s = get_next_segment (&q, descsiz, seg, sizeof (seg))))
        (*p->log_fn) ("%*s%s\n", width, "", s);

    return;
}
コード例 #2
0
ファイル: reg.cpp プロジェクト: killvxk/ring3k
NTSTATUS create_parse_key( regkey_t *&key, UNICODE_STRING *name, bool& opened_existing )
{
	while (name->Length && do_open_subkey( key, name, true ))
		/* repeat */ ;

	opened_existing = (name->Length == 0);

	while (name->Length)
	{
		UNICODE_STRING seg;

		skip_slashes( name );

		seg.Length = get_next_segment( name );
		seg.Buffer = name->Buffer;

		key = new regkey_t( key, &seg );
		if (!key)
			return STATUS_NO_MEMORY;

		name->Buffer += seg.Length/2;
		name->Length -= seg.Length;
	}

	return STATUS_SUCCESS;
}
コード例 #3
0
ファイル: reg.cpp プロジェクト: killvxk/ring3k
ULONG do_open_subkey( regkey_t *&key, UNICODE_STRING *name, bool case_insensitive )
{
	ULONG len;

	skip_slashes( name );

	len = get_next_segment( name );
	if (!len)
		return len;

	for (regkey_iter i(key->children); i; i.next())
	{
		regkey_t *subkey = i;
		if (len != subkey->name.Length)
			continue;
		if (case_insensitive)
		{
			if (strncmpW( name->Buffer, subkey->name.Buffer, len/sizeof(WCHAR) ))
				continue;
		}
		else
		{
			if (memcmp( name->Buffer, subkey->name.Buffer, len/sizeof(WCHAR) ))
				continue;
		}

		// advance
		key = subkey;
		name->Buffer += len/2;
		name->Length -= len;
		return len;
	}

	return 0;
}
コード例 #4
0
ファイル: reg.cpp プロジェクト: killvxk/ring3k
NTSTATUS open_parse_key( regkey_t *&key, UNICODE_STRING *name, bool case_insensitive  )
{
	while (name->Length && do_open_subkey( key, name, case_insensitive ))
		/* repeat */ ;

	if (name->Length)
	{
		trace("remaining = %pus\n", name);
		if (name->Length == get_next_segment( name ))
			return STATUS_OBJECT_NAME_NOT_FOUND;

		return STATUS_OBJECT_PATH_NOT_FOUND;
	}

	return STATUS_SUCCESS;
}
コード例 #5
0
ファイル: optparse.c プロジェクト: surajpkn/flux-core
static void
optparse_doc_print (optparse_t p, struct optparse_option *o, int columns)
{
    char seg [128];
    char buf [4096];
    char *s;
    char *q;

    strncpy (buf, o->usage, sizeof (buf) - 1);
    q = buf;

    while ((s = get_next_segment (&q, columns, seg, sizeof (seg))))
        (*p->log_fn) ("%s\n", s);

    return;
}
コード例 #6
0
ファイル: urinorm.c プロジェクト: azzmosphere/Azzmos-0.1.1
/* 
 * ===  FUNCTION  ======================================================================
 *         Name:  uri_remove_dot_segments
 *  Description:  Implements RFC 3986 section 5.2.4 
 *                use for interpreting and removing the special "." and ".." complete 
 *                path segments from a referenced path.  This is done after the path is
 *                extracted from a reference, whether or not the path was relative, in
 *                order to remove any invalid or extraneous dot-segments prior to
 *                forming the target URI.  Although there are many ways to accomplish
 *                this removal process, we describe a simple method using two string
 *                buffers.
 *                
 * =====================================================================================
 */
extern char *
uri_remove_dot_segments( char **path )
{
	char *ou_buffer = NULL,
	     *in_buffer = NULL,
	     *segment   = NULL,
	     sl = '\0';
	int len = 0;
	if( *(path) == NULL ) {
		return NULL;
	}
	in_buffer = strdup( *(path));
	len = strlen( in_buffer ) + 1;
	ou_buffer = (char *) malloc( len );
	ou_buffer[0] = '\0';
	while( in_buffer != NULL ){
		segment = get_next_segment( &in_buffer);
		if( strcmp( segment, "../") == 0 || strcmp(segment,"./") == 0){
			shift_segment( &in_buffer, 0);
		}
		else if( strcmp(segment, "/./") == 0 || strcmp(segment,"/.") == 0){
			replace_prefix( &in_buffer);
		}
		else if( strcmp( segment,"/../") == 0 || strcmp(segment,"/..") == 0){
			replace_prefix(&in_buffer);
			pop_segment(&ou_buffer);
		}
		else if( strcmp( in_buffer, ".") == 0 || strcmp( in_buffer, "..") == 0){
			in_buffer = NULL;
		}
		else if( segment) {
			sl = segment[ strlen(segment) - 1];	
			if( sl == '/'){
				segment = shift_segment(&in_buffer, 0);
			}
			else {
				segment = shift_segment(&in_buffer, 1);
			}
			strcat(ou_buffer, segment);
		}
	}
	len = strlen(ou_buffer) + 1;
	realloc( (void *) ou_buffer, len);
	return ou_buffer;
}
コード例 #7
0
ファイル: ksegsel.c プロジェクト: CDarrow/Spectator-JinX
// ---------- select current segment ----------
int SelectCurrentSegForward()
{
	int	newseg_num,newside;

	get_next_segment(Cursegp-Segments,Curside,&newseg_num,&newside);

	if (newseg_num != Cursegp-Segments) {
		Cursegp = &Segments[newseg_num];
		Curside = newside;
		Update_flags |= UF_ED_STATE_CHANGED;
		if (Lock_view_to_cursegp)
			set_view_target_from_segment(Cursegp);

		med_create_new_segment_from_cursegp();
		mine_changed = 1;
	}

	return 1;
}
コード例 #8
0
ファイル: sptape.c プロジェクト: 4nykey/rockbox
void play_tape(void)
{
  static dbyte impbuf[IMPBUFLEN];

  static int clevel;
  static dbyte *impbufp;
  static int impbufrem;
  static long imprem;
  
  static int cleared_buffers = 1;
 
  int tsn;
  dbyte *ibp;
  byte *tsp;
  int ibr;
  long ir;
  int cl;
  signed char *op;
  int ov;
  int ca;

  tsp = sp_tape_impinfo;
  op  = sp_tape_sound;
  tsn = TMNUM;
  
  if(!playing) {
    if(cleared_buffers) return;

    sp_playing_tape = 0;

    if(!clevel) {
      ca = CHKTICK;
      clevel = ~clevel;
    }
    else {
      ca = 0;
      cleared_buffers = 1;
    }
    imprem = CHKTICK * TMNUM;
  }
  else if(!sp_playing_tape) {
    sp_playing_tape = 1;
    cleared_buffers = 0;
    
    impbufrem = 0;
    imprem = 0;
    clevel = get_level() ? ~(0) : 0;
    if(clevel) ca = 0;
    else ca = 1;
  }
  else ca = 0;

#ifdef DEBUG_TAPE
  if(((clevel ? 1 : 0) ^ 
      (DANM(ula_inport) & EARBIT ? 1 : 0) ^ 
      (DANM(imp_change) ? 1 : 0) ^ 
      (ca ? 1 : 0)) == 0) 
    fprintf(stderr, "Levels don't match %i %i\n", imprem, impbufrem);
#endif

  cl = clevel;
  ibr = impbufrem;
  ir = imprem;
  ibp = impbufp;

  if(cl) ov = CHKTICK/2;
  else ov = -(CHKTICK/2);

  do {
    if(ir > 0) {
      *tsp++ = ca;
      *op++ = ov;
      ir -= CHKTICK;
      tsn--;
      if(!tsn) goto done;

      if(cl) ov = CHKTICK/2;
      else   ov = -(CHKTICK/2);

      while(ir > 0) {
    *tsp++ = 0;
    *op++ = ov;
    ir -= CHKTICK;
    tsn--;
    if(!tsn) goto done;
      }
      ca = 0;
    }
    if(ibr) {
      if(!ca) {
    if(cl) {
      ov += ir; 
      ca = (CHKTICK/2) - ov + 1;
    }
    else {
      ov -= ir;
      ca = ov + (CHKTICK/2) + 1;
    }
      }
      else {
    ca = 0;
    if(cl) ov += ir;
    else   ov -= ir;
      }
      ir += *ibp++;
      ibr--;
      cl = ~cl;
    }
    else {
      ibp = impbuf;
      do {
    ibr = next_imps(impbuf, IMPBUFLEN, CHKTICK * tsn);
    if(ibr) break;
    get_next_segment();
    if(!playing) {
      if(!cl) {
        if(ca) ca = 0;
        else   ca = CHKTICK;
        cl = ~cl;
      }
      ir = tsn*CHKTICK;
      ov = -(CHKTICK/2);
      break;
    }
      } while(1);
    }

  } while(1);

 done:

  clevel = cl;
  impbufrem = ibr;
  imprem = ir;
  impbufp = ibp;

  if(segtype >= SEG_DATA) { 
    int datak;
    
    datak = (int) (get_segpos() / 1000);
    if(datak > lastdatak) {
      if(ingroup) rb->snprintf(msgbuf,MAXDESCLEN, "%4d: ", currseg);
      else        rb->snprintf(msgbuf,MAXDESCLEN,  "      ");
      rb->snprintf(msgbuf+rb->strlen(msgbuf),MAXDESCLEN,  "%3dk", datak);
      put_tmp_msg(msgbuf);

      lastdatak = datak;
    }
  }
}