Beispiel #1
0
int
main(int argc, char *argv[]) {
  int n = 100;
  int i, k, x[100], y[100];

  // emulando calloc
  for (i = 0; i < n; ++i) {
    x[i] = 0;
    y[i] = 0;
  }

  for (i = 0; i < n; i++) {
    x[i] = i + 1;
  }
  for (k=0; k<1000; k++) {
//    for (i = n-1; i >= 0; i--) {
    for (i = 0; i < n; i++) {
      y[i] += x[i];
    }
  }

  printnum(y[0]);
  print(" ");
  printnum(y[n-1]);
  print("\n");

  return(0);
}
Beispiel #2
0
Datei: port.c Projekt: jaw0/jlisp
int prnport(Obj p, Obj s, int h){
	int (*fnc)(Obj,Obj,int);
	int t = SUBPORT(p);

	fnc = pdesc[t].print;

	if(fnc)
		return fnc(p, s, h);
	else{
		writestr(s, "#<ioport:");
		if( RPORTP(p))
			writechar(s, 'R');
		if( WPORTP(p))
			writechar(s, 'W');
		if( SUBPORT(p)){
			writechar(s, '_');
			printnum(s, SUBPORT(p), 16, 0, 0);
			if( SUBSUBPORT(p)){
				writechar(s, ':');
				printnum(s, SUBSUBPORT(p), 16, 0, 0);
			}
		}
		writechar(s, '>');
		return 1;
	}
}
Beispiel #3
0
int main()
{
	freopen("palsquare.in","r",stdin);
	freopen("palsquare.out","w",stdout);
	bnumber *bn = (bnumber *)calloc(1,sizeof(bnumber));
	bnumber *bp = (bnumber *)calloc(1,sizeof(bnumber));
	int base,i;
	scanf("%d",&base);
	bn->base = bp->base = base;
	for(i = 1;i <= 300;i++)
	{
		setdata(i * i,bp);
		if(is_prlindormic(bp->data,bp->length))
		{
			setdata(i,bn);
			printnum(bn->data,bn->length);
			printf(" ");
			printnum(bp->data,bp->length);
			printf("\n");
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
void control(void)
{
	if (read_encoder_time(LEFT) == 0 || read_encoder_time(RIGHT) == 0) return;
	static long int I = 0;
	long int P = 0;
	printnum(read_encoder_time(LEFT));
	print(">>");
	printnum(read_encoder_time(RIGHT));
	print(">>");
	long int diff = (read_encoder_time(LEFT) - read_encoder_time(RIGHT))>> 4;
	printnum(diff);
	print("--");
	I += diff * KI;
	P = diff * KP;
	
	pow_right = ((uint16_t)pow_right + I + P) > 255? 255:(pow_right + I + P) < MIN_POW? MIN_POW: (pow_right + I + P);
	pow_left = ((uint16_t)pow_right - (I + P)) > 255? 255:(pow_right - (I + P)) < MIN_POW? MIN_POW: (pow_right - (I + P));
	
	printnum(I);
	print("--");
	printnum(P);
	print("--");
	printnum(read_encoder_time(RIGHT));
	print("-");
	printnum(read_encoder_time(LEFT));
	print("-");
	printnum(pow_right);
	print(" ");
	printnum(pow_left);
	print("\n");
}
Beispiel #5
0
// One day, this'll show a bar. Ran out of time back then
unsigned char changeNumber(unsigned char currvalue, unsigned char maxvalue, DELTA *delta)
{
	unsigned char output = changeValue(currvalue, maxvalue,delta);

	put(VFD_CR);
	printnum(output);
	print("/");
	printnum(maxvalue);
	print("  ");

	return output;
}
Beispiel #6
0
/*
 * (probably unsafe) implementation of printf 
 */
int print_format(const char* str, ...){
	va_list ap;
	int i=0,j=0;
	int arg;
	va_start(ap,str);
	char charInt[12] ={0}; // maximum size of printable variable
	
	memset(out, 0, sizeof(out));

	while(str != NULL && *str != '\0' && i < 512){
		if(*str == '%'){
			switch(*++str){
				case 'x':{
						 arg = va_arg(ap, int);
						 printnum(charInt,12,"%x",arg);
						 for(j=0;j<12;j++){
							 if(charInt[j] != '\0'){
								 out[i++] = charInt[j];
							 }else{
								 str++;
								 break;
							 }
						 }
					 }
					 break;
				case 'd':{
						 arg = va_arg(ap, int);
						 printnum(charInt,12,"%d",arg);
						 for(j=0;j<12;j++){
							 if(charInt[j] != '\0'){
								 out[i++] = charInt[j];
							 }else{
								 str++;
								 break;
							 }
						 }
					 }
					 break;
				default:{
						out[i++]='%';
						out[i++]=*str++;
					}
					break;
			}
		}else{
			out[i++]=*str++;
		}
	}
Beispiel #7
0
static void
printnum(void (*putch)(int, void*), void *putdat,
	 unsigned long long num, unsigned base, int width, int padc)
{
	// if cprintf'parameter includes pattern of the form "%-", padding
	// space on the right side if neccesary.
	// you can add helper function if needed.
	// your code here:
	if (padc == '-' && width > judge_time_for_space) {
		judge_time_for_space = width;
	}

	// first recursively print all preceding (more significant) digits
	if (num >= base) {
		printnum(putch, putdat, num / base, base, width - 1, padc);
	} else {
		// print any needed pad characters before first digit
		if (padc == '-') {
			num_of_space = width - 1;
		} else {
			while (--width > 0)
				putch(padc, putdat);
		}
	}

	// then print this (the least significant) digit
	putch("0123456789abcdef"[num % base], putdat);
	// judge if it is time to put space
	if (padc == '-' && width == judge_time_for_space) {
		while(num_of_space-- > 0)
			putch(' ', putdat);
		num_of_space = 0;
		judge_time_for_space = 0;
	}
}
Beispiel #8
0
int
sys_stime(struct tcb *tcp)
{
	if (exiting(tcp)) {
		printnum(tcp, tcp->u_arg[0], "%ld");
	}
	return 0;
}
Beispiel #9
0
static void _cmd_status()
{
    unsigned long elapsed;
    ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
	elapsed = ticks;
    }
    elapsed = elapsed * timerTick_us / 1000000;
    printnum(elapsed);
    softuart_puts_P(" / ");
    printnum(timeoutTicks * timerTick_us / 1000000);
    softuart_puts_P("\r\n");

    // Print the last stored timestamp.
    byte c;
    byte i = 0;
    while ((c = read1EEPROM(i++)))
	softuart_putchar(c);
    softuart_puts_P("\r\n");
}
Beispiel #10
0
static void printNDigits_helper(string & num, int index) {
    if (index==num.length()) {
        printnum(num);
        return;
    }
    for (int i=0; i<10; i++) {
        num[index] = i+'0';
        printNDigits_helper(num, index+1);
    }
}
Beispiel #11
0
void kmain(ol_mmap_register_t mmr)
{
	textinit();
	clearscreen();

	println("The openLoader kernel is executing. \n");

	print("Current stack pointer: ");
	ol_registers_t regs = getregs();
	printnum(regs->esp, 16, FALSE, FALSE);
	putc(0xa);

	char status = inb(0x60);
	if((status & 2) == 2)
	{
		println("The A20 gate is open.");
		putc(0xa);
	}
	
	pic_init();
	setIDT();
	outb(OL_KBC_COMMAND, OL_KB_INIT);	// enable the keyboard

// display mmap
	init_mmap(mmr);
	println("Multiboot memory map:\n");
	display_mmap(mmr);

#if 0
	uint8_t active = ide_init(bootdrive);
	ide_read(0x100, 1<<20, &bootdrive[active], 60);
	uint8_t eax = ata_identify();
	printnum(active, 16, FALSE, FALSE);
#endif

	putc(0xa);

	println("Waiting for service interrupts..");
	while(1) halt();
	println("End of program reached!");
	endprogram();
}
Beispiel #12
0
int main()
{


   printnum(8);



    return 0;

}
Beispiel #13
0
void factorial() {
    uint n, i;
    len = 0;
    buff[0] = 1;
    printf("Enter a number:");
    scanf("%u", &n);
    for(i=1; i<=n; i++) {
	multiply(i);
    }
    printf("factorial(%d) = ", n);
    printnum();
}
Beispiel #14
0
static void
fixdotplot(wordlist *wl)
{
    char *s;
    char numbuf[128]; /* Printnum Fix */
    double *d, d1, d2;

    while (wl) {
        wl->wl_word = fixem(wl->wl_word);

        /* Is this a trailing (a,b) ? Note that we require it to be
         * one word.
         */
        if (!wl->wl_next && (*wl->wl_word == '(')) /*)*/ {
            s = wl->wl_word + 1;
            d = ft_numparse(&s, FALSE);
            if (*s != ',') {
                fprintf(cp_err, "Error: bad limits \"%s\"\n",
                        wl->wl_word);
                return;
            }
            d1 = *d;
            s++;
            d = ft_numparse(&s, FALSE);
            if ((*s != /*(*/ ')') || s[1]) {
                fprintf(cp_err, "Error: bad limits \"%s\"\n",
                        wl->wl_word);
                return;
            }
            d2 = *d;
            tfree(wl->wl_word);
            wl->wl_word = copy("xlimit");
            printnum(numbuf, d1);
            wl_append_word(NULL, &wl, copy(numbuf));
            printnum(numbuf, d2);
            wl_append_word(NULL, &wl, copy(numbuf));
        }
        wl = wl->wl_next;
    }
}
Beispiel #15
0
void printnum ( int begin )    //Simply have it keep incrementing a variable passed in, and then output the variable twice:
                               //once before the function recurses, and once after.
{
    begin = begin * 2 ;
    printf( "%d", begin );
    if ( begin < 70 )         /* The base case is when begin is no longer */
    {                           /* less than 9 */
        printnum ( begin + 1 );
    }
    /* display begin again after we've already printed everything from 1 to 9
     * and from 9 to begin + 1 */
       printf( "%d", begin );
}
Beispiel #16
0
void printnum(long n, void (*p)()){
	if(n < 0){
		printf("n is negative .\n");
		(*p)('-');
		n = -n;
	}

	if(n >= 10)
		printnum(n/10, p);

	(*p)("0123456789"[n % 10]);

}
Beispiel #17
0
static bool await_kb_ack(uint8_t value)
{
        uint8_t val;
top:
        while((inb(OL_KBC_STATUS_REGISTER) & 0x2) != 0);
        outb(OL_KBC_DATA_PORT, value);
        while((inb(OL_KBC_STATUS_REGISTER) & 0x1) == 0);
        val = inb(OL_KBC_DATA_PORT);
        if(val == 0xfe) goto top;

        printnum((uint32_t) val, 16, FALSE, FALSE);
        return TRUE;
}
int main(int argc, _TCHAR* argv[])
{
	srand(time(NULL));
	
	for (int x = 0; x < 10; x++){
		numeros[x] = std::rand() % 20 + 1;
	}

	remplazarnum(20, 2);
	borrar(5);
	buscarnum(12);
	printnum();
	return 0;
}
Beispiel #19
0
static void printnum(void (*putch)(int, void*), void *putdat,
	 unsigned  long long num, unsigned base, int width, int padc)
{
	// first recursively print all preceding (more significant) digits
	if (num >= base) {
		printnum(putch, putdat, num / base, base, width - 1, padc);
	} else {
		// print any needed pad characters before first digit
		while (--width > 0)
			putch(padc, putdat);
	}

	// then print this (the least significant) digit
	putch("0123456789abcdef"[num % base], putdat);
}
Beispiel #20
0
void exponentiation() {
    int n, i;
    len = 0;
    buff[0] = 1;
    printf("Enter a number:");
    scanf("%d", &n);
    int k = (n>>13)<<13;
    for(i=0; i<k; i+=13) {
	multiply(1<<13);
    }
    for(;i<n;i++)
	multiply(2);
    printf("2^%d = ", n);
    printnum();
}
Beispiel #21
0
int
sys_getpmsg(struct tcb *tcp)
{
    int i, flags;

    if (entering(tcp)) {
        /* fd */
        tprintf("%lu, ", tcp->u_arg[0]);
    } else {
        if (syserror(tcp)) {
            tprintf("%#lx, %#lx, %#lx, %#lx", tcp->u_arg[1],
                    tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[4]);
            return 0;
        }
        /* control and data */
        for (i = 1; i < 3; i++)
            printstrbufarg(tcp, tcp->u_arg[i], 1);
        /* pointer to band */
        printnum(tcp, tcp->u_arg[3], "%d");
        tprints(", ");
        /* pointer to flags */
        if (tcp->u_arg[4] == 0)
            tprints("NULL");
        else if (umove(tcp, tcp->u_arg[4], &flags) < 0)
            tprints("[?]");
        else {
            tprints("[");
            printflags(pmsgflags, flags, "MSG_???");
            tprints("]");
        }
        /* decode return value */
        switch (tcp->u_rval) {
        case MORECTL:
            tcp->auxstr = "MORECTL";
            break;
        case MORECTL|MOREDATA:
            tcp->auxstr = "MORECTL|MOREDATA";
            break;
        case MOREDATA:
            tcp->auxstr = "MORECTL";
            break;
        default:
            tcp->auxstr = NULL;
            break;
        }
    }
    return RVAL_HEX | RVAL_STR;
}
Beispiel #22
0
/* *
 * printnum - print a number (base <= 16) in reverse order
 * @putch:      specified putch function, print a single character
 * @fd:         file descriptor
 * @putdat:     used by @putch function
 * @num:        the number will be printed
 * @base:       base for print, must be in [1, 16]
 * @width:      maximum number of digits, if the actual width is less than @width, use @padc instead
 * @padc:       character that padded on the left if the actual width is less than @width
 * */
static void
printnum(void (*putch)(int, void*, int), int fd, void *putdat,
        unsigned long long num, unsigned base, int width, int padc) {
    unsigned long long result = num;
    unsigned mod = do_div(result, base);

    // first recursively print all preceding (more significant) digits
    if (num >= base) {
        printnum(putch, fd, putdat, result, base, width - 1, padc);
    } else {
        // print any needed pad characters before first digit
        while (-- width > 0)
            putch(padc, putdat, fd);
    }
    // then print this (the least significant) digit
    putch("0123456789abcdef"[mod], putdat, fd);
}
int main()
{
	friendclass fc(5);
	printnum(&fc);

	friendstrcut fs;
	friendfun(&fs);
	
	friendclassA fca(fc);
	std::cout << fca.num << std::endl;
	
	friendclassA fca01(fs);
	std::cout << fca01.num << std::endl;

	
	return 0;
}
Beispiel #24
0
static void
printnum(void (*putch)(int, void*), void *putdat,
	 unsigned long long num, unsigned base, int width, int padc)
{
	// if cprintf'parameter includes pattern of the form "%-", padding
	// space on the right side if neccesary.
	// you can add helper function if needed.
	// your code here:
	if (padc == '-' && width > padding_max_width)
		padding_max_width = width;

	// first recursively print all preceding (more significant) digits
	if (num >= base) {
		if (padc == '-' && one_number_flag == 0)
			one_number_flag = 2;
		printnum(putch, putdat, num / base, base, width - 1, padc);
	} else {
		if (padc == '-' && one_number_flag == 0)
			one_number_flag = 1;
		// print any needed pad characters before first digit
		while (--width > 0) {
			if (padc != '-')
				putch(padc, putdat);
			else
				padding_space++;
		}
	}

	// then print this (the least significant) digit
	putch("0123456789abcdef"[num % base], putdat);
	if ((width == padding_max_width || one_number_flag == 1) && padc == '-') {
		while(padding_space-- > 0)
			putch(' ', putdat);
		padding_space = 0;
		padding_max_width = 0;
		one_number_flag = 0;
	}
}
Beispiel #25
0
void
com_diff(wordlist *wl)
{
    double vntol, abstol, reltol, tol, cmax, cm1, cm2;
    struct plot *p1, *p2 = NULL;
    struct dvec *v1, *v2;
    double d1, d2;
    ngcomplex_t c1, c2, c3;
    int i, j;
    char *v1_name;          /* cannonical v1 name */
    char *v2_name;          /* cannonical v2 name */
    NGHASHPTR crossref_p;   /* cross reference hash table */
    SPICE_DSTRING ibuf;     /* used to build cannonical name */
    wordlist *tw;
    char numbuf[BSIZE_SP], numbuf2[BSIZE_SP], numbuf3[BSIZE_SP], numbuf4[BSIZE_SP]; /* For printnum */

    if (!cp_getvar("diff_vntol", CP_REAL, &vntol))
        vntol = 1.0e-6;
    if (!cp_getvar("diff_abstol", CP_REAL, &abstol))
        abstol = 1.0e-12;
    if (!cp_getvar("diff_reltol", CP_REAL, &reltol))
        reltol = 0.001;

    /* Let's try to be clever about defaults. This code is ugly. */
    if (!wl || !wl->wl_next) {
        if (plot_list && plot_list->pl_next && !plot_list->pl_next->pl_next) {
            p1 = plot_list;
            p2 = plot_list->pl_next;
            if (wl && !eq(wl->wl_word, p1->pl_typename) &&
                !eq(wl->wl_word, p2->pl_typename)) {
                fprintf(cp_err, "Error: no such plot \"%s\"\n",
                        wl->wl_word);
                return;
            }
            fprintf(cp_err, "Plots are \"%s\" and \"%s\"\n",
                    plot_list->pl_typename,
                    plot_list->pl_next->pl_typename);
            if (wl)
                wl = NULL;
        } else {
            fprintf(cp_err, "Error: plot names not given.\n");
            return;
        }
    } else {
        for (p1 = plot_list; p1; p1 = p1->pl_next)
            if (eq(wl->wl_word, p1->pl_typename))
                break;
        if (!p1) {
            fprintf(cp_err, "Error: no such plot %s\n", wl->wl_word);
            return;
        }
        wl = wl->wl_next;
    }

    if (!p2) {
        for (p2 = plot_list; p2; p2 = p2->pl_next)
            if (eq(wl->wl_word, p2->pl_typename))
                break;
        if (!p2) {
            fprintf(cp_err, "Error: no such plot %s\n", wl->wl_word);
            return;
        }
        wl = wl->wl_next;
    }

    /* Now do some tests to make sure these plots are really the
     * same type, etc.
     */
    if (!eq(p1->pl_name, p2->pl_name))
        fprintf(cp_err,
                "Warning: plots %s and %s seem to be of different types\n",
                p1->pl_typename, p2->pl_typename);
    if (!eq(p1->pl_title, p2->pl_title))
        fprintf(cp_err,
                "Warning: plots %s and %s seem to be from different circuits\n",
                p1->pl_typename, p2->pl_typename);

    /* This may not be the best way to do this.  It wasn't :).  The original
     * was O(n2) - not good.  Now use a hash table to reduce it to O(n). */
    for (v1 = p1->pl_dvecs; v1; v1 = v1->v_next)
        v1->v_link2 = NULL;

    spice_dstring_init(&ibuf);
    crossref_p = nghash_init(NGHASH_MIN_SIZE);
    nghash_unique(crossref_p, FALSE);

    for (v2 = p2->pl_dvecs; v2; v2 = v2->v_next) {
        v2->v_link2 = NULL;
        v2_name = cannonical_name(v2->v_name, &ibuf);
        nghash_insert(crossref_p, v2_name, v2);
    }

    for (v1 = p1->pl_dvecs; v1; v1 = v1->v_next) {
        v1_name = cannonical_name(v1->v_name, &ibuf);
        for (v2 = nghash_find(crossref_p, v1_name);
             v2;
             v2 = nghash_find_again(crossref_p, v1_name))
        {
            if (!v2->v_link2 &&
                ((v1->v_flags & (VF_REAL | VF_COMPLEX)) ==
                 (v2->v_flags & (VF_REAL | VF_COMPLEX))) &&
                (v1->v_type == v2->v_type))
            {
                v1->v_link2 = v2;
                v2->v_link2 = v1;
                break;
            }
        }
    }

    spice_dstring_free(&ibuf);
    nghash_free(crossref_p, NULL, NULL);

    for (v1 = p1->pl_dvecs; v1; v1 = v1->v_next)
        if (!v1->v_link2)
            fprintf(cp_err,
                    ">>> %s vector %s in %s not in %s, or of wrong type\n",
                    isreal(v1) ? "real" : "complex",
                    v1->v_name, p1->pl_typename, p2->pl_typename);

    for (v2 = p2->pl_dvecs; v2; v2 = v2->v_next)
        if (!v2->v_link2)
            fprintf(cp_err,
                    ">>> %s vector %s in %s not in %s, or of wrong type\n",
                    isreal(v2) ? "real" : "complex",
                    v2->v_name, p2->pl_typename, p1->pl_typename);

    /* Throw out the ones that aren't in the arg list */
    if (wl && !eq(wl->wl_word, "all")) {    /* Just in case */
        for (v1 = p1->pl_dvecs; v1; v1 = v1->v_next)
            if (v1->v_link2) {
                for (tw = wl; tw; tw = tw->wl_next)
                    if (nameeq(v1->v_name, tw->wl_word))
                        break;
                if (!tw)
                    v1->v_link2 = NULL;
            }
        for (v2 = p2->pl_dvecs; v2; v2 = v2->v_next)
            if (v2->v_link2) {
                for (tw = wl; tw; tw = tw->wl_next)
                    if (nameeq(v2->v_name, tw->wl_word))
                        break;
                if (!tw)
                    v2->v_link2 = NULL;
            }
    }

    /* Now we have all the vectors linked to their twins.  Travel
     * down each one and print values that differ enough.
     */
    for (v1 = p1->pl_dvecs; v1; v1 = v1->v_next) {
        if (!v1->v_link2)
            continue;
        v2 = v1->v_link2;
        if (v1->v_type == SV_VOLTAGE)
            tol = vntol;
        else
            tol = abstol;
        j = MAX(v1->v_length, v2->v_length);
        for (i = 0; i < j; i++) {
            if (v1->v_length <= i) {
                fprintf(cp_out,
                        ">>> %s is %d long in %s and %d long in %s\n",
                        v1->v_name, v1->v_length,
                        p1->pl_typename, v2->v_length, p2->pl_typename);
                break;
            } else if (v2->v_length <= i) {
                fprintf(cp_out,
                        ">>> %s is %d long in %s and %d long in %s\n",
                        v2->v_name, v2->v_length,
                        p2->pl_typename, v1->v_length, p1->pl_typename);
                break;
            } else {
                if (isreal(v1)) {
                    d1 = v1->v_realdata[i];
                    d2 = v2->v_realdata[i];
                    if (MAX(fabs(d1), fabs(d2)) * reltol +
                        tol < fabs(d1 - d2)) {
                        printnum(numbuf, d1);
                        fprintf(cp_out,
                                "%s.%s[%d] = %-15s ",
                                p1->pl_typename, v1->v_name, i, numbuf);
                        printnum(numbuf, d2);
                        fprintf(cp_out,
                                "%s.%s[%d] = %s\n",
                                p2->pl_typename, v2->v_name, i, numbuf);
                    }
                } else {
                    c1 = v1->v_compdata[i];
                    c2 = v2->v_compdata[i];
                    realpart(c3) = realpart(c1) - realpart(c2);
                    imagpart(c3) = imagpart(c1) - imagpart(c2);
                    /* Stupid evil PC compilers */
                    cm1 = cmag(c1);
                    cm2 = cmag(c2);
                    cmax = MAX(cm1, cm2);
                    if (cmax * reltol + tol < cmag(c3)) {

                        printnum(numbuf, realpart(c1));
                        printnum(numbuf2, imagpart(c1));
                        printnum(numbuf3, realpart(c2));
                        printnum(numbuf4, imagpart(c2));

                        fprintf(cp_out,
                                "%s.%s[%d] = %-10s, %-10s %s.%s[%d] = %-10s, %s\n",
                                p1->pl_typename, v1->v_name, i,
                                numbuf,
                                numbuf2,
                                p2->pl_typename, v2->v_name, i,
                                numbuf3,
                                numbuf4);
                    }
                }
            }
        }
    }
}
Beispiel #26
0
void prnobj(Obj a, Obj stream, int how){
	int typ = TYPEOFX(a);
	int (*printfnc)(Obj,Obj,int);
	char buf[8];
	char *foo;
	Obj radix;
	int base;
	
	switch( typ ){
	  case TPVF_IMMED:
		if( INUMP( a )){
			/* int */
			radix = getvalue( sym_oradix);
			if(DEFINEDP(radix)&& INUMP(radix))
				base = CINT(radix);
			else
				base = 10;
			if(how) base = 10;
			printnum(stream, CINT(a), base, 0,0);
		} else if( ICHARP( a )){
			/* char */
			foo = 0;
			if(how){
				writestr(stream, "#\\");
				foo = spec_repr( CCHAR(a), 0 );
			}
			if(foo)
				writestr(stream, foo);
			else
				writechar(stream, CCHAR(a));
		} else if( ICONSTP( a )){
			/* const sym */
			switch( a ){

			  case IC_NIL:
				writestr(stream, "()");
				break;

			  case IC_TRUE:
				writestr(stream, "#t");
				break;

			  case IC_FALSE:
				writestr(stream, "#f");
				break;

			  case IC_UNDEF:
				writestr(stream, "#<undefined>");
				break;

			  case IC_UNSPEC:
				writestr(stream, "#<unspecified>");
				break;

			  case IC_EOF:
				writestr(stream, "#<EOF>");
				break;

			  default:
				writestr(stream, "#<<send in bug report> IC_0x");
				printnum(stream, a, 16,0,0);
				writestr(stream, "?>");
				break;
			}
		} else if ( SYMBOLP( a )){
			writestr(stream, symbolname(a) );
		} else {
			writestr(stream, "#<<send in bug report> IMM_0x");
			printnum(stream, a, 16,0,0);
			writestr(stream, "?>");
		}
		break;
#if 0
	  case TPV_SYMBOL:
		writestr(stream, CCHARS(a));
		break;
#endif
	  case TPV_SYM_BOX:
		if(how)
			writestr(stream, symbolname( MAKSYM(CSYM_BOX(a)->id )));
		else{
			writestr(stream, "#<[");
			writestr(stream, symbolname( MAKSYM(CSYM_BOX(a)->id )));
			writestr(stream, "]>");
		}
		break;

	  default:
		printfnc = jlisp_vtbl[ typ ].print;

		if( !printfnc || ! printfnc(a, stream, how) ){
			writestr(stream, "#<_");
			printnum(stream, typ, 10,0,0);
			writestr(stream, "_0x");
			printnum(stream, a, 16, 0,0);
			writestr(stream, ">");
		}
		break;
	}
}
Beispiel #27
0
int test_lists() {
  int len = 0;
  // create a list of integers (li1) from 1 to SIZE
  DLL *li1 = list_sequence(1, SIZE);
  // copy the list to li2
  DLL *li2 = list_copy(li1);
  // remove each individual item from left side of li2 and
  // append to right side of li3 (preserving order)
  DLL *li3 = list_new();
  // compare li2 and li1 for equality
  if (!list_equal(li2, li1)) {
    print("li2!=li1\n");
    while(1);
  }
  while (!list_empty(li2)) {
    list_push_tail(li3, list_pop_head(li2));
  }
  // li2 must now be empty
  if (!list_empty(li2)) {
    print("li2 ne\n");
    while(1);
  }
  // remove each individual item from right side of li3 and
  // append to right side of li2 (reversing list)
  while (!list_empty(li3)) {
    list_push_tail(li2, list_pop_tail(li3));
  }
  // li3 must now be empty
  if (!list_empty(li3)) {
    print( "li3 ne\n");
    while(1);
  }
  // reverse li1 in place
  list_reverse(li1);
  // check that li1's first item is now SIZE
  if (list_first(li1)->val != SIZE) {
    print( "li1 stw\n");
    while(1);
  }
  // check that li1's last item is now 1
  if (list_last(li1)->val != 1) {
    print( "lstw\n");
    while(1);
  }
  // check that li2's first item is now SIZE
  if (list_first(li2)->val != SIZE) {
    print( "li2 stw\n");
    while(1);
  }
  // check that li2's last item is now 1
  if (list_last(li2)->val != 1) {
    print( "lstw\n");
    while(1);
  }

  // check that li1's length is still SIZE
  if (list_length(li1) != SIZE) {
    print( "li1 szw\n");
    while(1);
  }
  // compare li1 and li2 for equality
  if (!list_equal(li1, li2)) {
    print( "li1!=li2\n");
    while(1);
  }
  len = list_length(li1);
  //  free(li1);
  //  free(li2);
  //  free(li3);
  // return the length of the list
  printnum(len);
  print("\n");

  return  0;
}
Beispiel #28
0
void
com_print(wordlist *wl)
{
    struct dvec *v, *lv = NULL, *bv, *nv, *vecs = NULL;
    int i, j, ll, width = DEF_WIDTH, height = DEF_HEIGHT, npoints, lineno;
    struct pnode *pn, *names;
    struct plot *p;
    bool col = TRUE, nobreak = FALSE, noprintscale, plotnames = FALSE;
    bool optgiven = FALSE;
    char *s, *buf, *buf2; /*, buf[BSIZE_SP], buf2[BSIZE_SP];*/
    char numbuf[BSIZE_SP], numbuf2[BSIZE_SP]; /* Printnum buffers */
    int ngood;

    if (wl == NULL)
        return;

    buf = TMALLOC(char, BSIZE_SP);
    buf2 = TMALLOC(char, BSIZE_SP);

    if (eq(wl->wl_word, "col")) {
        col = TRUE;
        optgiven = TRUE;
        wl = wl->wl_next;
    } else if (eq(wl->wl_word, "line")) {
        col = FALSE;
        optgiven = TRUE;
        wl = wl->wl_next;
    }

    ngood = 0;
    names = ft_getpnames(wl, TRUE);
    for (pn = names; pn; pn = pn->pn_next) {
        if ((v = ft_evaluate(pn)) == NULL)
            continue;
        if (!vecs)
            vecs = lv = v;
        else
            lv->v_link2 = v;
        for (lv = v; lv->v_link2; lv = lv->v_link2)
            ;
        ngood += 1;
    }

    if (!ngood)
        goto done;

    /* See whether we really have to print plot names. */
    for (v = vecs; v; v = v->v_link2)
        if (vecs->v_plot != v->v_plot) {
            plotnames = TRUE;
            break;
        }

    if (!optgiven) {
        /* Figure out whether col or line should be used... */
        col = FALSE;
        for (v = vecs; v; v = v->v_link2)
            if (v->v_length > 1) {
                col = TRUE;
                /* Improvement made to print cases @[sin] = (0 12 13 100K) */
                if ((v->v_plot->pl_scale && v->v_length != v->v_plot->pl_scale->v_length) && (*(v->v_name) == '@'))
                {
                    col = FALSE;
                }
                break;
            }
        /* With this I have found that the vector has less elements than the SCALE vector
         * in the linked PLOT. But now I must make sure in case of a print @vin[sin] or
         * @vin[pulse]
         * for it appear that the v->v_name begins with '@'
         * And then be in this case.
         */
    }

    out_init();
    if (!col) {
        if (cp_getvar("width", CP_NUM, &i))
            width = i;
        if (width < 60)
            width = 60;
        if (width > BSIZE_SP - 2)
            buf = TREALLOC(char, buf, width + 1);
        for (v = vecs; v; v = v->v_link2) {
            char *basename = vec_basename(v);
            if (plotnames)
                (void) sprintf(buf, "%s.%s", v->v_plot->pl_typename, basename);
            else
                (void) strcpy(buf, basename);
            tfree(basename);

            for (s = buf; *s; s++)
                ;
            s--;
            while (isspace(*s)) {
                *s = '\0';
                s--;
            }
            ll = 10;

            /* v->v_rlength = 1 when it comes to make a print @ M1 and does not want to come out on screen
             * Multiplier factor [m]=1
             *  @M1 = 0,00e+00
             * In any other case rlength not used for anything and only applies in the copy of the vectors.
             */
            if (v->v_rlength == 0) {
                if (v->v_length == 1) {
                    if (isreal(v)) {
                        printnum(numbuf, *v->v_realdata);
                        out_printf("%s = %s\n", buf, numbuf);
                    } else {
                        printnum(numbuf, realpart(v->v_compdata[0]));
                        printnum(numbuf2, imagpart(v->v_compdata[0]));
                        out_printf("%s = %s,%s\n", buf, numbuf, numbuf2);
                    }
                } else {
                    out_printf("%s = (  ", buf);
                    for (i = 0; i < v->v_length; i++)
                        if (isreal(v)) {

                            printnum(numbuf, v->v_realdata[i]);
                            (void) strcpy(buf, numbuf);
                            out_send(buf);
                            ll += (int) strlen(buf);
                            ll = (ll + 7) / 8;
                            ll = ll * 8 + 1;
                            if (ll > width) {
                                out_send("\n\t");
                                ll = 9;
                            } else {
                                out_send("\t");
                            }
                        } else {
                            /*DG*/
                            printnum(numbuf, realpart(v->v_compdata[i]));
                            printnum(numbuf2, imagpart(v->v_compdata[i]));
                            (void) sprintf(buf, "%s,%s", numbuf, numbuf2);
                            out_send(buf);
                            ll += (int) strlen(buf);
                            ll = (ll + 7) / 8;
                            ll = ll * 8 + 1;
                            if (ll > width) {
                                out_send("\n\t");
                                ll = 9;
                            } else {
                                out_send("\t");
                            }
                        }
                    out_send(")\n");
                } //end if (v->v_length == 1)
            }  //end  if (v->v_rlength == 1)
        }  // end for loop
    } else {    /* Print in columns. */
        if (cp_getvar("width", CP_NUM, &i))
Beispiel #29
0
int main(){
	long x = -145l;
	printnum(x, (void (*)())func);   // clever !!!!!

	return 0;
}
Beispiel #30
0
int
ft_cktcoms(bool terse)
{
    wordlist *coms, *command, all;
    char *plottype, *s;
    struct dvec *v;
    static wordlist twl = { "col", NULL, NULL };
    struct plot *pl;
    int i, found;
    char numbuf[BSIZE_SP]; /* For printnum*/

    all.wl_next = NULL;
    all.wl_word = "all";

    if (!ft_curckt)
        return 1;

    plot_cur = setcplot("op");
    if (!ft_curckt->ci_commands && !plot_cur)
        goto nocmds;
    coms = ft_curckt->ci_commands;
    cp_interactive = FALSE;

    /* Listing */
    if (ft_listprint) {
        if (terse)
            fprintf(cp_err, ".options: no listing, rawfile was generated.\n");
        else
            inp_list(cp_out, ft_curckt->ci_deck, ft_curckt->ci_options, LS_DECK);
    }

    /* If there was a .op line, then we have to do the .op output. */
    plot_cur = setcplot("op");
    if (plot_cur != NULL) {
        assert(plot_cur->pl_dvecs != NULL);
        if (plot_cur->pl_dvecs->v_realdata != NULL) {
            if (terse) {
                fprintf(cp_out, "OP information in rawfile.\n");
            } else {
                fprintf(cp_out, "\t%-30s%15s\n", "Node", "Voltage");
                fprintf(cp_out, "\t%-30s%15s\n", "----", "-------");
                fprintf(cp_out, "\t----\t-------\n");
                for (v = plot_cur->pl_dvecs; v; v = v->v_next) {
                    if (!isreal(v)) {
                        fprintf(cp_err,
                                "Internal error: op vector %s not real\n",
                                v->v_name);
                        continue;
                    }
                    if ((v->v_type == SV_VOLTAGE) && (*(v->v_name) != '@')) {
                        printnum(numbuf, v->v_realdata[0]);
                        fprintf(cp_out, "\t%-30s%15s\n", v->v_name, numbuf);
                    }
                }
                fprintf(cp_out, "\n\tSource\tCurrent\n");
                fprintf(cp_out, "\t------\t-------\n\n");
                for (v = plot_cur->pl_dvecs; v; v = v->v_next)
                    if (v->v_type == SV_CURRENT) {
                        printnum(numbuf, v->v_realdata[0]);
                        fprintf(cp_out, "\t%-30s%15s\n", v->v_name, numbuf);
                    }
                fprintf(cp_out, "\n");

                if (!ft_nomod)
                    com_showmod(&all);
                com_show(&all);
            }
        }
    }

    for (pl = plot_list; pl; pl = pl->pl_next)
        if (ciprefix("tf", pl->pl_typename)) {
            if (terse) {
                fprintf(cp_out, "TF information in rawfile.\n");
                break;
            }
            plot_cur = pl;
            fprintf(cp_out, "Transfer function information:\n");
            com_print(&all);
            fprintf(cp_out, "\n");
        }

    /* Now all the '.' lines */
    while (coms) {
        command = cp_lexer(coms->wl_word);
        if (!command)
            goto bad;
        if (eq(command->wl_word, ".width")) {
            do
                command = command->wl_next;
            while (command && !ciprefix("out", command->wl_word));
            if (command) {
                s = strchr(command->wl_word, '=');
                if (!s || !s[1]) {
                    fprintf(cp_err, "Error: bad line %s\n", coms->wl_word);
                    coms = coms->wl_next;
                    continue;
                }
                i = atoi(++s);
                cp_vset("width", CP_NUM, &i);
            }
        } else if (eq(command->wl_word, ".print")) {
            if (terse) {
                fprintf(cp_out,
                        ".print line ignored since rawfile was produced.\n");
            } else {
                command = command->wl_next;
                if (!command) {
                    fprintf(cp_err, "Error: bad line %s\n", coms->wl_word);
                    coms = coms->wl_next;
                    continue;
                }
                plottype = command->wl_word;
                command = command->wl_next;
                fixdotprint(command);
                twl.wl_next = command;
                found = 0;
                for (pl = plot_list; pl; pl = pl->pl_next)
                    if (ciprefix(plottype, pl->pl_typename)) {
                        plot_cur = pl;
                        com_print(&twl);
                        fprintf(cp_out, "\n");
                        found = 1;
                    }
                if (!found)
                    fprintf(cp_err, "Error: .print: no %s analysis found.\n",
                            plottype);
            }
        } else if (eq(command->wl_word, ".plot")) {
            if (terse) {
                fprintf(cp_out,
                        ".plot line ignored since rawfile was produced.\n");
            } else {
                command = command->wl_next;
                if (!command) {
                    fprintf(cp_err, "Error: bad line %s\n",
                            coms->wl_word);
                    coms = coms->wl_next;
                    continue;
                }
                plottype = command->wl_word;
                command = command->wl_next;
                fixdotplot(command);
                found = 0;
                for (pl = plot_list; pl; pl = pl->pl_next)
                    if (ciprefix(plottype, pl->pl_typename)) {
                        plot_cur = pl;
                        com_asciiplot(command);
                        fprintf(cp_out, "\n");
                        found = 1;
                    }
                if (!found)
                    fprintf(cp_err, "Error: .plot: no %s analysis found.\n",
                            plottype);
            }
        } else if (ciprefix(".four", command->wl_word)) {
            if (terse) {
                fprintf(cp_out,
                        ".fourier line ignored since rawfile was produced.\n");
            } else {
                int err;

                plot_cur = setcplot("tran");
                err = fourier(command->wl_next, plot_cur);
                if (!err)
                    fprintf(cp_out, "\n\n");
                else
                    fprintf(cp_err, "No transient data available for "
                            "fourier analysis");
            }
        } else if (!eq(command->wl_word, ".save") &&
                   !eq(command->wl_word, ".op") &&
                   // !eq(command->wl_word, ".measure") &&
                   !ciprefix(".meas", command->wl_word) &&
                   !eq(command->wl_word, ".tf"))
        {
            goto bad;
        }
        coms = coms->wl_next;
    }

nocmds:
    /* Now the node table
       if (ft_nodesprint)
       ;
    */

    /* The options */
    if (ft_optsprint) {
        fprintf(cp_out, "Options:\n\n");
        cp_vprint();
        (void) putc('\n', cp_out);
    }

    /* And finally the accounting info. */
    if (ft_acctprint) {
        static wordlist ww = { "everything", NULL, NULL };
        com_rusage(&ww);
    } else if ((!ft_noacctprint) && (!ft_acctprint)) {
        com_rusage(NULL);
    }
    /* absolutely no accounting if noacct is given */

    putc('\n', cp_out);
    return 0;

bad:
    fprintf(cp_err, "Internal Error: ft_cktcoms: bad commands\n");
    return 1;
}