Exemple #1
0
void testWordlen() {
	T* word = NULL;
	CU_ASSERT_EQUAL(wordlen(word), 0);
	word = "";
	CU_ASSERT_EQUAL(wordlen(word), 0);
	word = " ";
	CU_ASSERT_EQUAL(wordlen(word), 0);
	word = "bebe";
	CU_ASSERT_EQUAL(wordlen(word), 4);
	word = "bebe  bebe";
	CU_ASSERT_EQUAL(wordlen(word), 4);
}
Exemple #2
0
extern VMRef
VMalloc(
	int	size,
	VMRef	v )
{
	VMRef res;
	VMpage *page = &VMTable[page_(v)];

	if( offset_(v) != 0 ) error("VM: VMalloc not called on base ref: %x",v);
	
	VMLRU();

	size = wordlen(size);
	
	if( page->left < size )
	{
		*(int *)&res = -1;
		return res;
	}
	
	MakeVMRef( res, page_( v ), (word)VMPageSize - page->left );

	page->left -= size;

	page->status |= VMdirty;	/* ensure it is dirtied */
	
	return res;
}
Exemple #3
0
T* arrayProcessing(T* array) {
	if (!array || !*array || countWordsArray(array) < 2) {
		return NULL;
	}
	T* dst = (T*)malloc(dstlen(strlen(array)+1)*sizeof(T));
	T* dstEnd = dst;
	*dstEnd = 0;
	T* firstWord = findFirstWord(array);
	T* curr = findNextWord(firstWord);
	while(curr) {
		if (cmpWithFirstWord(firstWord, curr)) {
			curr = findNextWord(curr);
			continue;
		}
		else {
			if (dstEnd != dst && *dstEnd != ' ') {
				*(dstEnd++) = ' ';
			}
			dstEnd = wordProcessingArray(curr, dstEnd, wordlen(curr));
			if (dstEnd != dst && *(dstEnd-1) == ' ') {
				dstEnd--;
			}
			*dstEnd = 0;
		}
		curr = findNextWord(curr);
	}
	dstEnd--;
	if (*dstEnd == ' ') {
		*dstEnd = 0;
	}
	return (T*)realloc(dst, (strlen(dst)+1)*sizeof(T));
}
Exemple #4
0
int cmpWithFirstWord(T* firstWord, T* word) {
	size_t i = 0, j = 0;
	if (!word) {
		return 0;
	}
	if (wordlen(firstWord) != wordlen(word)) {
		return 0;
	}
	if (word[i] != firstWord[j]) {
		return 0;
	}
	while (!isWordEnd(word[++i]) && !isWordEnd(firstWord[++j])) {
		if (word[i] != firstWord[j]) {
			return 0;
		}
	}
	return 1;
}
Exemple #5
0
static int32_t opt_howto_do ( uint8_t cmd, uint8_t _save, struct opt_type *opt, struct opt_parent *patch, struct ctrl_node *cn ) {
	
	static uint8_t call_counter;
	struct opt_parent *p;
	
	if ( cmd == OPT_REGISTER ) {
		
		call_counter = 0;
	
	} else if ( cmd == OPT_CHECK ) {
		
		if( wordlen( patch->p_val )+1 >= MAX_ARG_SIZE )
			return FAILURE;
		
	} else if ( cmd == OPT_APPLY ) {
		
		call_counter++;
		
		dbgf_cn( cn, DBGL_CHANGES, DBGT_INFO, 
		        "now called for the %d time: going to store: %s", 
		         call_counter, patch->p_val );
		
		dbgf( DBGL_CHANGES, DBGT_INFO, "%s - but currently still stored: %s", 
		      opt_cmd2str[cmd], (p=get_opt_parent_val( opt, 0 )) ? p->p_val : NULL );
		
	} else if ( cmd == OPT_SET_POST ) {
		
		// this block will always be executed 
		// after all options with this order were set and
		// before any option with a higher order is set
		
		dbgf( DBGL_CHANGES, DBGT_INFO, "%s - now stored: %s", 
		      opt_cmd2str[cmd], (p=get_opt_parent_val( opt, 0 )) ? p->p_val : NULL );
		
		
	} else if ( cmd == OPT_POST ) {
		
		//this block will always be executed after all options were set
		
		if ( !on_the_fly ) {
			//due to NOT on_the_fly 
			//this block will only be executed once during init after all options were set
		}
		
	} else if ( cmd == OPT_UNREGISTER ) {
	
	}
	
	return SUCCESS;
}
Exemple #6
0
extern VMRef
VMNew( int size )
{
   VMRef v;

   size = wordlen(size);

   v = VMalloc(size,vmheap);
   
   if( NullRef(v) ) 
   {
      vmheap = VMPage();
      v = VMalloc(size,vmheap);
   }

        VMDirty(v);

   return v;
}
/*
 * Extracts given chains from a policy file.
 */
static int
openpam_read_chain(pam_handle_t *pamh,
	const char *service,
	pam_facility_t facility,
	const char *filename,
	openpam_style_t style)
{
	pam_chain_t *this, **next;
	const char *p, *q;
	int count, i, lineno, ret;
	pam_facility_t fclt;
	pam_control_t ctlf;
	char *line, *name;
	FILE *f;

	if ((f = fopen(filename, "r")) == NULL) {
		openpam_log(errno == ENOENT ? PAM_LOG_LIBDEBUG : PAM_LOG_NOTICE,
		    "%s: %m", filename);
		return (0);
	}
	this = NULL;
	count = lineno = 0;
	while ((line = openpam_readline(f, &lineno, NULL)) != NULL) {
		p = line;

		/* match service name */
		if (style == pam_conf_style) {
			if (!match_word(p, service)) {
				FREE(line);
				continue;
			}
			p = next_word(p);
		}

		/* match facility name */
		for (fclt = 0; fclt < PAM_NUM_FACILITIES; ++fclt)
			if (match_word(p, _pam_facility_name[fclt]))
				break;
		if (fclt == PAM_NUM_FACILITIES) {
			openpam_log(PAM_LOG_NOTICE,
			    "%s(%d): invalid facility '%.*s' (ignored)",
			    filename, lineno, wordlen(p), p);
			goto fail;
		}
		if (facility != fclt && facility != PAM_FACILITY_ANY) {
			FREE(line);
			continue;
		}
		p = next_word(p);

		/* include other chain */
		if (match_word(p, "include")) {
			p = next_word(p);
			if (*next_word(p) != '\0')
				openpam_log(PAM_LOG_NOTICE,
				    "%s(%d): garbage at end of 'include' line",
				    filename, lineno);
			if ((name = dup_word(p)) == NULL)
				goto syserr;
			ret = openpam_load_chain(pamh, name, fclt);
			FREE(name);
			if (ret < 0)
				goto fail;
			count += ret;
			FREE(line);
			continue;
		}

		/* allocate new entry */
		if ((this = calloc(1, sizeof *this)) == NULL)
			goto syserr;

		/* control flag */
		for (ctlf = 0; ctlf < PAM_NUM_CONTROL_FLAGS; ++ctlf)
			if (match_word(p, _pam_control_flag_name[ctlf]))
				break;
		if (ctlf == PAM_NUM_CONTROL_FLAGS) {
			openpam_log(PAM_LOG_ERROR,
			    "%s(%d): invalid control flag '%.*s'",
			    filename, lineno, wordlen(p), p);
			goto fail;
		}
		this->flag = ctlf;

		/* module name */
		p = next_word(p);
		if (*p == '\0') {
			openpam_log(PAM_LOG_ERROR,
			    "%s(%d): missing module name",
			    filename, lineno);
			goto fail;
		}
		if ((name = dup_word(p)) == NULL)
			goto syserr;
		this->module = openpam_load_module(name);
		FREE(name);
		if (this->module == NULL)
			goto fail;

		/* module options */
		p = q = next_word(p);
		while (*q != '\0') {
			++this->optc;
			q = next_word(q);
		}
		this->optv = calloc(this->optc + 1, sizeof(char *));
		if (this->optv == NULL)
			goto syserr;
		for (i = 0; i < this->optc; ++i) {
			if ((this->optv[i] = dup_word(p)) == NULL)
				goto syserr;
			p = next_word(p);
		}

		/* hook it up */
		for (next = &pamh->chains[fclt]; *next != NULL;
		     next = &(*next)->next)
			/* nothing */ ;
		*next = this;
		this = NULL;
		++count;

		/* next please... */
		FREE(line);
	}
	if (!feof(f))
		goto syserr;
	fclose(f);
	return (count);
 syserr:
	openpam_log(PAM_LOG_ERROR, "%s: %m", filename);
 fail:
	FREE(this);
	FREE(line);
	fclose(f);
	return (-1);
}
/*****
* The main function.
*****/
void main(void)
{
    FILE	*infile;        /* Input file. */
    char	linebfr[1024],  /* Input line buffer, very long for safety. */
            *wordptr;       /* Pointer to next word in linebfr. */
    int     i;            /* Scratch variable. */
    static int	wordlencnt[MAXWORDLEN],
            /* Word lengths are counted in elements 1 to
             MAXWORDLEN. Element 0 isn't used. The array is
             static so that the elements need not be set to
             zero at run time. */
            overlencnt;     /* Overlength words are counted here. */

    printf("WARNING: This is an example program for the practice\n");
    printf("debugging session.  If you are not running this under the\n");
    printf("Integrated Development Environment press control-break now.\n");
    printf("See the debugging chapter of the User's Guide for details.\n\n");

    printf( "Enter the input file's name: " );
    gets(linebfr);
    if ( !strlen(linebfr) ) {
        printf( "You must specify an input file name!\n" );
        exit();
    }

    infile = fopen( linebfr, "r" );
    if ( !infile ) {
        printf( "Can't open input file!\n" );
        exit();
    }

    /* Each loop processes one line. NOTE: if a line is longer than the
     input buffer the program may produce invalid results. The very large
     buffer makes this unlikely. */
    while (   fgets( linebfr, sizeof(linebfr), infile )   )   {
        printf("%s\n",linebfr);
        /* Check for buffer overflow & remove the trailing newline. */
        i = strlen(linebfr);
        if ( linebfr[i-1] != '\n' )
            printf( "Overlength line beginning\n\t%70s\n", linebfr );
        else
            linebfr[i-1] = NUL;

        /* lineptr points to the 1st word in linebfr (past leading spaces). */
        wordptr = nextword(linebfr);

        /* Each loop processes one word. The loop ends when [nextword]
           returns NULL, indicating there are no more words. */
        while (*wordptr) {
            /* Find the length of this word, increment the proper element of the
               length count array, & point to the space following the word. */
            i = wordlen(wordptr);
            if ( i > MAXWORDLEN )
                overlencnt++;
            else
                ;
            wordlencnt[i]++;
            wordptr += i;

            /* Find the next word (if any). */
            wordptr = nextword(wordptr);
        }
    }

    /* Print the word length counts. Each loop prints one. */
    printf(  "  Length Count\n" );
    for ( i=1; i<MAXWORDLEN; i++ )
        printf( "  %5d %5d\n", i, wordlencnt[i] );
    printf( "Greater %5d\n", overlencnt );

    /* Close the file & quit. */
    fclose(infile);
}