Esempio n. 1
0
int main(int argc, char **argv)
{
	HC_DEF_S(s);

	s_catz(s, "hello world of possibilities!");
	HC_SAFE_CSTR(s);

	fprintf(stdout, "[%i][%i][%s]\n", s->len, s->a, s->s);

	s->len = 0;  /* truncate string */

	s_catn(s, "hi ", 3);
	fwrite(s->s, s->len, 1, stdout);

	s_copyc(s, 'f');
	s_catz(s, "olk");
	s_catc(s, 's');
	s_catc(s, '!');
	s_catc(s, '\n');
	fwrite(s->s, s->len, 1, stdout);

	s_upper(s);
	fwrite(s->s, s->len, 1, stdout);

	s_lower(s);
	fwrite(s->s, s->len, 1, stdout);

	s_copyz(s, "aa");

	assert(sdiff("aa", "aa") == 0);
	assert(s_diffz(s, "aa") == 0);
	assert(s_diffn(s, "aa", slen("aa")) == 0);

	assert(sdiff("aa", "aaz") < 0);
	assert(s_diffz(s, "aaz") < 0);
	assert(s_diffn(s, "aaz", slen("aaz")) < 0);

	assert(sdiff("aa", "a0z") > 0);
	assert(s_diffz(s, "a0z") > 0);
	assert(s_diffn(s, "a0z", slen("a0z")) > 0);

	assert(sdiff("aa", "0") > 0);
	assert(s_diffz(s, "0") > 0);
	assert(s_diffn(s, "0", slen("0")) > 0);

	assert(sdiff("aa", "0zz") > 0);
	assert(s_diffz(s, "0zz") > 0);
	assert(s_diffn(s, "0zz", slen("0zz")) > 0);

	assert(sdiff("aa", "a") > 0);
	assert(s_diffz(s, "a") > 0);
	assert(s_diffn(s, "a", slen("a")) > 0);

	assert(sdiff("aa", "a0") > 0);
	assert(s_diffz(s, "a0") > 0);
	assert(s_diffn(s, "a0", slen("a0")) > 0);

	s_free(s);

	/*
	 */

	assert(s_cat_u4_hex(s, 0) == 1);
	assert(s_diffz(s, "0") == 0);
	print_s("[", s, "]\n");

	s->len = 0;
	assert(s_cat_i4_hex(s, 0) == 1);
	assert(s_diffz(s, "0") == 0);
	print_s("[", s, "]\n");

	s->len = 0;
	assert(s_cat_u4_hex(s, 0xffffffff) == 8);
	assert(s_diffz(s, "ffffffff") == 0);
	print_s("[", s, "]\n");

	s->len = 0;
	assert(s_cat_i4_hex(s, (int32_t)0xffffffff) == 2);
	assert(s_diffz(s, "-1") == 0);
	print_s("[", s, "]\n");

	s_free(s);

	/*
	 */

	assert(s_cat_u4_dec(s, 0) == 1);
	assert(s_diffz(s, "0") == 0);
	print_s("[", s, "]\n");

	s->len = 0;
	assert(s_cat_i4_dec(s, 0) == 1);
	assert(s_diffz(s, "0") == 0);
	print_s("[", s, "]\n");

	s->len = 0;
	assert(s_cat_u4_dec(s, 0xffffffff) == 10);
	assert(s_diffz(s, "4294967295") == 0);
	print_s("[", s, "]\n");

	s->len = 0;
	assert(s_cat_i4_dec(s, (int32_t)0xffffffff) == 2);
	assert(s_diffz(s, "-1") == 0);
	print_s("[", s, "]\n");

	s_free(s);

	/*
	 */

	assert(s_cat_u4_base36(s, 0) == 1);
	assert(s_diffz(s, "0") == 0);
	print_s("[", s, "]\n");

	s->len = 0;
	assert(s_cat_i4_base36(s, 0) == 1);
	assert(s_diffz(s, "0") == 0);
	print_s("[", s, "]\n");

	s->len = 0;
	assert(s_cat_u4_base36(s, 0xffffffff) == 7);
	assert(s_diffz(s, "1z141z3") == 0);
	print_s("[", s, "]\n");

	s->len = 0;
	assert(s_cat_i4_base36(s, (int32_t)0xffffffff) == 2);
	assert(s_diffz(s, "-1") == 0);
	print_s("[", s, "]\n");

	s_free(s);

	/*
	 */

	{
		void *out;
		int putlen;
		HC_DEF_S(t);

		s_copyz(s, "hello world of possibilities!");
		putlen = s_putlen(s);

		HC_ALLOC(out, putlen);

		assert(s_put(s, out) == putlen);
		assert(s_get(t, out) == putlen);
		assert(s_diff(s, t) == 0);

		s->len = 0;
		s_reprn(s, out, putlen);
		print_s("[", s, "]\n");

		HC_FREE(out);
		s_free(t);
	}

	/*
	 */

	s_free(s);

	return 0;
}
Esempio n. 2
0
File: zinit.c Progetto: E-LLP/VICAR
FUNCTION  FILE *z_init
(
#ifdef LARGE_PARBLK_FIX
    struct LARGE_PARBLK *block,         /* out: parameter block         */
#else
    struct	PARBLK	*block,		/* out: parameter block		*/
#endif
    FUNINT		mode		/* in: mode: P_ABORT or P_CONT  */

 )
    {
    IMPORT  FILE	*stdo_file;	/* pointer to stdout file	*/
    IMPORT  BOOL	term_std;	/* true if terminal is stdout   */
    IMPORT  CODE	applic_type;	/* application type ('c')	*/
    IMPORT  TEXT	pm_type[], pk_type[];
    struct VARIABLE	*v;
    CODE		termtype;
    COUNT		termlines;
    COUNT		termcols;
    TEXT		msgbuf[STRINGSIZ+1];
    TEXT		**stdr_ptr = 0;	/* stdrec string vector pointer	*/
    COUNT		len;
    CODE		code;
    TEXT		filemode[2];	/* create or append		*/
    FILE		*stdo_ptr;

    t_init(&termlines, &termcols, &termtype);	/* initialize terminal pkg */
#ifdef LARGE_PARBLK_FIX
    code = p_inim((struct PARBLK *)block, sizeof(struct LARGE_PARBLK), mode);    
#else
    code = p_inim(block, sizeof(struct PARBLK), mode);	
#endif
                                                /* receive parblk from TM  */
    if (code != SUCCESS)
	return (NULL);
    z_call ((struct PARBLK *)block);		/* application init	   */

    v = p_find ((struct PARBLK *)block, "_STDOUT");  /* get the string	*/	
    if ((*v).v_type != V_STRING)
      x_error ((*block).mode, pm_type, pk_type, (uintptr_t) "_STDOUT", 0, 0);
    else
	stdr_ptr = (TEXT **) (*v).v_cvp;	/* get value pointer	*/
    term_std = (s_equal(TERMINAL, stdr_ptr[0]));   /* filename = terminal ? */
#ifdef VICAR_BATCH_LOG
#ifdef VAX_VMS
    if (s_equal("SYS$OUTPUT:.;", stdr_ptr[0]))  /* alternate form of terminal */
        term_std = TRUE;
#endif
#endif
    s_copy("w", filemode);			/* assume create	    */
    if (!s_equal(stdr_ptr[1] , "CREATE"))
	s_copy("a", filemode);
#ifdef UNIX
    s_lower(stdr_ptr[0]);			/* make file name lower case */
#endif
    stdo_ptr = fopen(stdr_ptr[0], filemode);    	/* open the file */
    if (stdo_ptr == NULL)
	{
	if (mode == P_ABORT)
	    {
	    len = s_copy("Could not open standard output file ", msgbuf);
	    s_bcopy(stdr_ptr[0], &msgbuf[len], STRINGSIZ);
	    t_write(msgbuf, T_STDCC);			/* errmsg to terminal*/
	    z_exit(-1, "TAE-STDOPEN");			/* set SFI, SKEY     */
 	    }
	stdo_ptr = stdout;	/* Allow running with no terminal! */
				/* (without triggering shell-vicar) */
	}
    else
	stdo_file = stdo_ptr;			/* save stdout ptr globally */
    applic_type = C_TYPE;			/* 'c' language application */
    return (stdo_ptr);
    }
Esempio n. 3
0
FUNCTION CODE hard_help
(
    struct   SFILE	*fctx,		/* In: file context block for opened file	*/
    TEXT  		curlib[],	/* In: library name of opened file		*/
    TEXT		procname[],	/* In: proc name for LHS of help display	*/
    TEXT		outname[],	/* In: name of output file			*/
    struct  HELPBLK	*helpblk	/* out: help output control block		*/

)
{

    IMPORT  struct  VARIABLE *char_gbl;		/* system characteristics	*/

    struct DIRBLK	dirblk;		/* directive control block		*/
    struct TXTSTOR	title;		/* context for dynamically stored title text */
    struct SFILE	f;
    struct POSCTX	saved_pos;
    struct POSCTX	level2_pos;
    BOOL		has_level2;
    TEXT		str[STRINGSIZ+1];
    CODE		code;
    TEXT		field[STRINGSIZ+1];	/* text field after a directive	*/
    TEXT		name[STRINGSIZ+1];
    TEXT		key[KEYSIZ+1];
    TEXT		msg[STRINGSIZ+1];

    /* If no output name was given,	*/
    if (NULLSTR(outname))		/* use pdf or command name	*/
    {
        f_name(procname, outname);
        s_append(".MEM", outname);	/* procname.MEM for output	*/
    }

    /* note -- SAVELUN is safe because |save| qual is not allowed for this command */
    code = f_ophf(&f, SAVELUN, outname, F_WRITE);	/* open output file	*/
    if (code != SUCCESS)
    {
        sprintf(msg, "Error opening output, host code = %d", f.host_code);
        store_help_error(helpblk, msg, "TAE-OPNWRT");
        return(FAIL);
    }

    d_init(&dirblk, fctx, curlib, (TEXT **)(*char_gbl).v_cvp,
           (*char_gbl).v_count);    		/* init directive block		*/
    if ((*helpblk).compiled)			/* if PDF is compiled		*/
    {
        if ((code = prep_c_help(&dirblk, &title, msg, key)) != SUCCESS)	/* prepare*/
            goto put_error;
        str[0] = EOS;
    }
    else					/* PDF is not compiled		*/
    {
        code = d_dirctv(&dirblk, str, field);
        if (s_equal(str, ".TITLE"))
        {   /* read the title into dynamic store			*/
            if ((code = gettitle(&dirblk, &title, msg, key))!= SUCCESS)
                goto put_error;
            code = d_dirctv(&dirblk, str, field);
        }
        else				/* no title */
        {
            title.numline = 0;
        }
    }

    code = put_title(&f, &title, msg, key);  /* start filling output file */
    if (code != SUCCESS) goto put_error;

    if (title.tp != NULL) fretxt(&title); /* free the dyamically-stored title	*/

    /* str should contain .HELP directive now.  If not, find it	*/
    if (! s_equal( str, ".HELP"))
    {
        code = d_search(&dirblk, ".HELP", field);
        if (code != SUCCESS)
        {
            store_help_error(helpblk, "No help available on '%s'.", "TAE-NOHELP");
            return (FAIL);
        }
    }

    code = put_text_block(&f, &dirblk, msg, key);	/* output general help	*/
    if (code != SUCCESS) goto put_error;

    code = d_search(&dirblk, ".LEVEL1", field);
    if (code != SUCCESS)		/* if there is no level1 help then */
        goto return_success;		/* assume we are done and exit	   */

    f_movpos(CURRENT_POS, &saved_pos);		/* save position in input */
    code = d_search(&dirblk, ".LEVEL2", field); /* find detailed help */
    has_level2 = (code == SUCCESS);
    if (has_level2)				/* if detailed help exists,  */
        f_movpos(CURRENT_POS, &level2_pos);	/* save the position in file */

    f_setpos(dirblk.sfileptr, &saved_pos);	/* reset position to curr pos */
    code = d_dirctv(&dirblk, str, name);	/* gives str=".TITLE"	     */

    while (1)
    {
        code = d_dirctv(&dirblk, str, name);
        if (code != SUCCESS)			/* if no more directives, we */
            break;				/* are done		     */

        if (s_equal(str, ".END") || s_equal(str, ".LEVEL2")) /* done */
            break;

        code = put_header(&f, &dirblk, str, name, msg, key);
        if (code != SUCCESS) goto put_error;
        if (has_level2)
            code = put_level2_text(&f, &dirblk, &level2_pos,
                                   str, name, msg, key);
        if (code != SUCCESS) goto put_error;
    }

return_success:
    f_close(&f, F_KEEP);
    s_lower(outname);
    sprintf(msg, "Wrote file \"%s\".", outname);
    put_stdout(msg);
    return (SUCCESS);

put_error:
    store_help_error(helpblk, msg, key);
    return (FAIL);
}