Example #1
0
void main() {
    double a,b,h;
    char a1[15],*p;

    a1[0] = 13;
    printf ("De el valor del primer cateto\n");
    cgets (a1);
    a = strtod (a1+2, &p);
    while (*p != '\0' || a <= 0) {
        printf ("%c",7);  		/* Aviso de error */
        printf ("Cifra incorrecta. Favor rectifique...\n");
        cgets (a1);
        a = strtod (a1+2,&p);
    }
    printf ("\n");
    printf ("De el valor del segundo cateto\n");
    cgets (a1);
    b = strtod (a1+2, &p);
    while (*p != '\0' || b <= 0) {
        printf ("%c",7);  		/* Aviso de error */
        printf ("Cifra incorrecta. Favor rectifique...\n");
        cgets (a1);
        b = strtod (a1+2,&p);
    }
    printf ("\n");
    h = hypot (a,b);
    printf ("Hipotenusa = %lf\n",h);
    getch();
}
Example #2
0
File: recv.c Project: eswartz/emul
void	getbasename(void)
{
	printf("\n\nReceiving a module.\n"
	       "Enter the base name for this module.  This is a 7-letter word used\n"
	       "in the filename to organize all the binary segments of the module.\n"
	       "(Example for Extended BASIC:  extbas)\n\n: ");
	basename[0]=8;
	cgets(basename);

	printf("\n\nEnter the name of the module.\n\n: ");
	title[0]=31;
	cgets(title);
}
Example #3
0
float get_float_input(void)
{
	char rx_buf[64];
	cgets( rx_buf, 64);
	
	return atof(rx_buf);
}
Example #4
0
static JSBool
js_conio_cgets(JSContext *cx, uintN argc, jsval *arglist)
{
	jsval *argv=JS_ARGV(cx, arglist);
	char	buf[258];
	int32	maxlen=255;
	char	*ret;
	jsrefcount	rc;

	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if(argc > 1)
		return(JS_FALSE);
	if(argc > 0) {
		if(!JSVAL_IS_NUMBER(argv[0]))
			return(JS_FALSE);
		if(!JS_ValueToInt32(cx, argv[0], &maxlen))
			return(JS_FALSE);
		if(maxlen > 255)
			return(JS_FALSE);
	}
	buf[0]=(char)maxlen;
	rc=JS_SUSPENDREQUEST(cx);
	ret=cgets(buf);
	JS_RESUMEREQUEST(cx, rc);
	if(ret==NULL)
		JS_SET_RVAL(cx, arglist,JSVAL_NULL);
	else {
		buf[257]=0;
		JS_SET_RVAL(cx, arglist,STRING_TO_JSVAL(JS_NewStringCopyZ(cx,ret)));
	}

	return(JS_TRUE);
}
Example #5
0
lea() {
	char a[10];

	a[0]=5;
	cgets (a);
	printf ("\n");
	return (atoi (a+2) );
}
Example #6
0
void main ()  {
	char a[40],b[40];

	a[0] = 38;
	b[0] = 38;
	printf ("De primer cadena: a[]\n");
	cgets(a);
	printf("\n");
	printf ("De segunda cadena: b[]\n");
	cgets(b);
	printf("\n");
	if (strcmp (a+2,b+2) > 0)
		PR("La cadena a[] es mayor que la cadena b[]");
	else if (strcmp (a+2,b+2) < 0)
		PR("La cadena a[] es menor que la cadena b[]");
	else PR("La cadena a[] es igual a la cadena b[]");
	getch();
}
Example #7
0
int			 _RTL_FUNC _cscanf(const char *__format, ...)
{
    va_list argptr;
    char buf[1024];
    cgets(buf);
    va_start( argptr, __format);
    vsscanf( buf,__format, argptr);
    va_end(argptr);
    return 0;
}
Example #8
0
void wait( void ) // Waits for <Enter>.
{
    char buff[20];

    #if defined(_NO_IO_REDIRECTION_)
        gets( buff );
    #else
        *buff = 4;
        cgets( buff);
    #endif
}
Example #9
0
int cscanf(const char *__format, ...)
{
	char buffer[MAX_BUFFER + 3];
	int r;
	va_list ap;
	buffer[0] = MAX_BUFFER;
	cgets(buffer);
	va_start(ap, __format);
	r = myvsscanf(buffer + 2, __format, ap);
	va_end(ap);
	return r;
}
Example #10
0
char *newFile(void)
{
	static char fname[FNSIZE];
	int c;

	gotoxy(1,25);
	textcolor(mcolor);
	textbackground(mbgrd);
	clreol();
	fname[0] = FNSIZE;
	cprintf("Enter file: ");
	return cgets(fname);
}
Example #11
0
int
main (void)
{
  char str[20];
  char *p;

#ifdef unix
  conio_init();
#endif

  /* read 17 chars, and a null terminator */

  str[0] = 18;

  /* Read a string at the end of a line */

  clrscr();

  gotoxy (78, 1);
  cputs ("This text should wrap");

  gotoxy (1, 5);
  cputs ("Enter a string:");

  gotoxy (1, 6);
  p = cgets (str);

  gotoxy (1, 19);
  cputs (p);

  gotoxy (1, 20);
  cputs ("Press any key to quit");
  getch();
  clrscr();

#ifdef unix
  conio_end();
#endif

  /* Print some results */

  printf ("%s = %d chars\n", p, strlen(p));
  printf ("str[0] = %d\n", str[0]);
  printf ("str[1] = %d\n", str[1]);
  exit (0);
}
Example #12
0
int	getname(char *old, char *nw)
{
	int	index;
	do
	{
		printf("Enter a correct name for \"%10s\", up to 10 characters:\n\n: ",
			old);
		nw[0]=10;
		cgets(nw);
		strupr(nw+2);
		printf("\n");
		for (index=strlen(nw+2); index<10; index++)
			nw[index+2]=0x20;
		nw[12]=0;
	}	while (!validatename(nw+2));

        return	1;
}
Example #13
0
// funkcia je konzolou chattu
void conCHATT()
{
  char chatt_buff[80];
  int i;

  // init chatt console - draw
  conDRAW_CHATT();

  while (conACTIVE == 1) {
    textattr(atrCONSOLE);
    cprintf("\n(%s)->(%s): ", myNICK, strangerNICK);
    textattr(atrBORDER);
    cgets(chatt_buff);
    comSENDROW(chatt_buff);
    for (i = 0; i < 80; i++)
      chatt_buff[i] = '\0';
  }
}
Example #14
0
// --- Função Principal
void main(){
    TRISC0 = 0;                        //Entrada em RC0 como saida
    PORTC = 0;
    UART_init();  // initialize the UART module
    ADCON0 = 0x00;
    ADCON1 = 0x06;
    CMCON = 0x07;
    GIE=0x01;// habilita interrupção global
    PEIE=0x01;//habilita interrupção por perifericos
    
    printf("*** Iniciando UART ***\n");
    while(1){                         //Loop Infinito       
        printf("Digite um numero:\n");
        cgets(entrada);
        printf("\nO numero digitado foi : ");
        printf("%s\n",entrada);
        manipula_entrada();
    } //end while
} //end main
Example #15
0
void main() {
	unsigned seg,desplaza;
	char prueba[10];
	int i;

	printf ("Antes de ejecutar este programa, desactive la tecla CAPS\n");
	printf ("Oprima una tecla...\n");
	getch();

	seg = 0x0040;
	desplaza = 0x0017;
	pokeb (seg, desplaza, 0x40);

	printf ("Escriba una cadena de caracteres\n");
	prueba [0] = 8;
	cgets (prueba);
	printf ("\n");
	printf ("%s\n",prueba+2);
	getch();
}
Example #16
0
char *cgetln(char strg[], int n)
{
 int i;
 char *ptr;

 if (n > 253)
    n = 253;

 curs_set(1);
 timeout(-1);

 buffer[0] = n;
 ptr = cgets(buffer);

 timeout(0);
 curs_set(0);

 cprintf("\n\r");
 
 if (ptr != NULL)
   {
    for (i=2; i<(n+2); i++)
      {
	    if ((buffer[i] == '\n') || (buffer[i] == 0))
		  {
		   strg[i-2] = 0;
		   break;
		  }
	   strg[i-2] = buffer[i];
	  }
	 strg[n] = 0; 
    return strg;
   }
 else
   {
    strg[0] = 0;
    return NULL;
   }
}
Example #17
0
void main()
{
   int Radius, Bands, i, j, LastIndex, BandsX2, LastBandStartIndex;
   int TopBandStartIndex, BottomBandStartIndex, FaceNum;
   struct Point3 BaseVec, BandVec, WorkingVec, TempVec;
   char OutputFilename[130];
   char Description[130];

   printf("Radius: ");
   scanf("%d",&Radius);
   printf("Bands: ");
   scanf("%d",&Bands);
   printf("Output file: ");
   OutputFilename[0] = 127;
   cgets(OutputFilename);
   printf("\nBrief description: ");
   Description[0] = 127;
   cgets(Description);
   printf("\n");

   BandsX2 = Bands*2;

   if ((OutputFile = fopen(&OutputFilename[2], "w")) == NULL) {
      printf("Error\n");
      exit(1);
   }

   /* Descriptive comments */
   fprintf(OutputFile, "/* %s */\n", &Description[2]);
   fprintf(OutputFile, "/* Created with radius = %d, bands = %d */\n",
         Radius, Bands);

   /* Defines for # of faces and vertices */
   fprintf(OutputFile, "#define NUM_FACES %d\n", BandsX2*Bands);
   fprintf(OutputFile, "#define NUM_VERTS %d\n\n",
         2+1+BandsX2*(Bands-1)+1+ (BandsX2*Bands));
   /* # of vertices excluding unit normal endpoints */
   fprintf(OutputFile, "#define NUM_REAL_VERTS %d\n\n",
         2+1+BandsX2*(Bands-1)+1);

   /* Do the polygon vertices */
   fprintf(OutputFile, "Point3 Verts[] = {\n");

	/* Generate the rotation matrices */
   AppendRotationY(YXform, PI / Bands);
   AppendRotationZ(ZXform, PI / Bands);

   /* Do the point at the top */
   BaseVec.X = 0.0;
   BaseVec.Y = Radius;
   BaseVec.Z = 0.0;
   BaseVec.W = 1.0;
   PrintVertex(&BaseVec);

   BandVec = BaseVec;

   /* Do the vertices in each band in turn */
   for (i=1; i<Bands; i++) {
      /* Rotate around Z to the next band's latitude */
      XformVec(ZXform, (double *)&BandVec, (double *)&TempVec);
      WorkingVec = BandVec = TempVec;
		/* Do the vertices in this band */
      for (j=0; j<BandsX2; j++) {
         WorkingVec = TempVec;
         PrintVertex(&WorkingVec);
         /* Now rotate around Y to the next vertex's longitude */
         XformVec(YXform, (double *)&WorkingVec, (double *)&TempVec);
      }
   }

   /* Do the point at the bottom */
   BaseVec.Y = -Radius;
   PrintVertex(&BaseVec);

   /* Now generate the unit normal endpoint for each face, as the last
      entries in the vertex list */
   /* Index in overall vertex list of first unit normal endpoint we'll
      create; remember where we can find it */
   FirstUnitNormalIndex = NumPoints;

   FaceNum = 0;

   /* Unit normal endpoints in top band */
   for (i=0; i<BandsX2; i++) {
      UnitNormal(&BaseVec, 0, ((i+1)%BandsX2)+1, i+1);
      PrintVertex(&BaseVec);
      FaceNum++;
   }

   /* Unit normal endpoints in middle bands */
   for (j=0; j<(Bands-2); j++) {
      TopBandStartIndex = j*BandsX2 + 1;
      BottomBandStartIndex = (j+1)*BandsX2 + 1;
		/* Indexes in this band */
      for (i=0; i<BandsX2; i++) {
         UnitNormal(&BaseVec, i+TopBandStartIndex,
               ((i+1)%BandsX2)+TopBandStartIndex,
               i+BottomBandStartIndex);
         PrintVertex(&BaseVec);
         FaceNum++;
      }
   }

   /* Unit normal endpoints in bottom band */
   LastIndex = BandsX2*(Bands-1)+1;
   LastBandStartIndex = BandsX2*(Bands-2)+1;
   for (i=0; i<BandsX2; i++) {
      UnitNormal(&BaseVec, LastBandStartIndex+i,
            LastBandStartIndex+((i+1)%BandsX2), LastIndex);
      PrintVertex(&BaseVec);
      FaceNum++;
   }

   /* Done generating points, including both polygon vertices and unit
      normals */
   fprintf(OutputFile, "};\n\n");


   /* Do the vertex indexes for each face in each band */
   FaceNum = 0;

   /* Vertex indexes in top band, with unit normal endpoint first */
   for (i=0; i<BandsX2; i++) {
      Print4Indexes(FaceNum++, FirstUnitNormalIndex++, 0,
            ((i+1)%BandsX2)+1, i+1);
   }

   /* Vertex indexes in middle bands, with unit normal endpoints first */
   for (j=0; j<(Bands-2); j++) {
      TopBandStartIndex = j*BandsX2 + 1;
      BottomBandStartIndex = (j+1)*BandsX2 + 1;
		/* Indexes in this band */
      for (i=0; i<BandsX2; i++) {
         Print5Indexes(FaceNum++, FirstUnitNormalIndex++,
               i+TopBandStartIndex,
               ((i+1)%BandsX2)+TopBandStartIndex,
               ((i+1)%BandsX2)+BottomBandStartIndex,
               i+BottomBandStartIndex);
      }
   }

   /* Vertex indexes in bottom band, with unit normal endpoint first */
   LastIndex = BandsX2*(Bands-1)+1;
   LastBandStartIndex = BandsX2*(Bands-2)+1;
   for (i=0; i<BandsX2; i++) {
      Print4Indexes(FaceNum++, FirstUnitNormalIndex++,
            LastBandStartIndex+i,
            LastBandStartIndex+((i+1)%BandsX2), LastIndex);
   }

   /* Do the list of pointers to index arrays for each face */
   fprintf(OutputFile, "\nstatic int *VertNumList[] = {\n");
   for (i=0; i<(BandsX2*Bands); i++) {
      fprintf(OutputFile, "Face%d,\n", i);
   }
   fprintf(OutputFile, "};\n");

   /* Do the # of vertices in each face (3 for the top and bottom
      bands, 4 for the rest) */
   fprintf(OutputFile, "\nstatic int VertsInFace[] = {\n");
   for (i=0; i<BandsX2; i++) fprintf(OutputFile, "3,\n");
   for (i=0; i<(BandsX2*(Bands-2)); i++) fprintf(OutputFile, "4,\n");
   for (i=0; i<BandsX2; i++) fprintf(OutputFile, "3,\n");
   fprintf(OutputFile, "};\n");

   exit(0);
}
Example #18
0
void main() {
    // clrscr
    uint8_t color;
    uint8_t bg;
    uint8_t x, y;
    uint8_t a;
    uint16_t b;
    char c;
    char *vram;
    unsigned char index;
    char buffer[20];
    unsigned char offs;

    // links, oben, rechts, unten
    window(3, 3, 30, 30);
    clrscr();
    for (color = 0; color < 16; color++) {
        textcolor(color);
        for (bg = 0; bg < 8; bg++) {
            textbackground(bg);
            cstbt(0x1b);
        }
        cputs("  Hello KC85!\r\n");
    }
    x = wherex();
    y = wherey();

    gotoxy(0, 3);
    delline();
    gotoxy(0, 5);
    delline();
    cputs("test");

    gotoxy(x, y);

    c = getche();
    putch(c);
    crlf();

    // kbhit

    textcolor(BROWN);
    clrscr();

    for (index = 0; index < 20; index++) {
        if ((index & 0x01) == 0x01)
            highvideo();
        else
            lowvideo();
        cputs("press key\r\n");
    }
    textcolor(WHITE);

    while (kbhit())
        cputs("you have touched key.\r\n");
    cputs("done\r\n");
    next();

    // delline
    cputs("This line will be deleted. press key.");
    getch();
    delline();
    cputs("Line deleted successfully.");
    getch();
    crlf();

    // inlin

    cputs("Zeug eingeben: ");
    offs = wherex();
    vram = inlin();
    vram += offs;
    crlf();

    index = 0;
    while (*vram != '\0') {
        buffer[index] = *vram;
        index++;
        vram++;
    }
    ahex(index);
    while (index > 0) {
        index--;
        ahex(buffer[index]);
        space();
    }
    next();
    crlf();

    // cgets
    cputs("Zeug eingeben: ");
    buffer[0] = 10;
    vram = cgets(buffer);
    crlf();
    delline();
    index = buffer[1];
    ahex(index);
    space();
    space();

    while (index > 0) {
        index--;
        ahex(*vram);
        space();
        vram++;
    }
    ahex(*vram);
    crlf();

    // add test
    a = sqr(100);
    b = puse(10, 10, 10);
    b = b + a;
    hlhx(b);
    crlf();
}
Example #19
0
char *
gets(char * s)
{
	return cgets(s);
}
Example #20
0
File: main.c Project: vbmacher/qsOS
int main()
{
  int key;
  int sel, old_sel;

  printf("\nLoading...");

  Init_PHY();
  Init_LOG();
  Init_APP();

  sel = 0;
  old_sel = 0;
start:
  mainmenu(sel);

  // kbhit
  fflush(stdin);
  key = 0;
  asm {
    mov ax, 0x0305
    xor bx, bx
    int 0x16
  }
key_loop:
  while (!kbhit()) ;
  asm {
    xor ah, ah
    int 0x16
    mov byte ptr [key], ah // scan kod
  }

  switch (key) {
    case 0x50: // dole
      old_sel = sel;
      sel++;
      if (sel == menu_count) sel = 0;
      sel_item(sel,old_sel);
      goto key_loop;
    case 0x48: // hore
      old_sel = sel;
      if (!sel) sel = menu_count;
      sel--;
      sel_item(sel, old_sel);
      goto key_loop;
    case 0xE0:
    case 0x1C: // enter
      break;
    default:
      goto key_loop;
  }

  draw_window();
  switch (sel) {
    case CREATE_FILE:
      create_file(NULL);
      break;
    case DELETE_FILE:
      delete_file(NULL);
      break;
    case WRITE_FILE:
      write_file(NULL,NULL,0,0,1);
      cprintf("\n\rPress ENTER");
      cgets(NULL);
      break;
    case READ_FILE:
      read_file(NULL,NULL,0,0,1);
      cprintf("\n\rPress ENTER");
      cgets(NULL);
      break;
    case CREATE_DIR:
      create_dir(NULL);
      break;
    case DELETE_DIR:
      delete_dir(NULL);
      break;
    case SHOW_DIR:
      show_dir();
      break;
    case SET_PATH:
      set_path(NULL);
      break;
    case DISK_INFO:
      disk_info();
      break;
    case FORMAT_FDD:
      format_fdd();
      break;
    case FDD_TEST:
      dotest_fdd();
      break;
    case ABOUT:
      about();
      break;
    case EXIT:
      goto ext;
  }

  textattr(BORDER);
  cprintf("\n\r\n\rPress any key to continue...");
  getchar();
  goto start;

ext:
  window(1,1,80,25);
  textattr(0x07);
  clrscr();

  Destroy_APP();
  Destroy_LOG();
  Destroy_PHY();

  return 0;
}
Example #21
0
inst_t
install_top (dat_t *dat_ary, int dat_count)
{
  /* Top-level piece for the install program.  Determines what disk
     sets the user wants to install, then installs them. */

  char *s;                          /* used for retrieving localized text */
  char txtfile[MAXPATH];            /* name of text descr file */
  int ch;
  int i;
  inst_t ret;                       /* return: no. of errors,warnings */
  inst_t this;                      /* no. of errors,warnings */

  /* Where to install from, to */

  if (!fromdirflag || !destdirflag) /* only prompt if one or both are missing */
  do {

    /* get directories from user */

    repaint_empty();

    fromdir[0] = MAXDIR;		/* max length of the string */
    destdir[0] = MAXDIR;		/* max length of the string */

    s = catgets (cat, SET_PROMPT_LOC, MSG_INSTALLFROM, MSG_INSTALLFROM_STR);
    gotoxy (5, 10);
    cputs (s);

    gotoxy (5, 12);
    if (fromdirflag)
      cputs(&(fromdir[2]));
    else
      cgets (fromdir);

    s = catgets (cat, SET_PROMPT_LOC, MSG_INSTALLTO, MSG_INSTALLTO_STR);
    gotoxy (5, 16);
    cputs (s);
      
    gotoxy (5, 18);
    if (destdirflag)
      cputs(&(destdir[2]));
    else
      cgets (destdir);

    /* let user verify */

    repaint_empty();
    gotoxy (5, 10);
    cputs (catgets (cat, SET_PROMPT_LOC, MSG_WILLINSTALLFROM, MSG_WILLINSTALLFROM_STR));
    gotoxy (5, 11);
    cputs (&fromdir[2]);
    gotoxy (5, 13);
    cputs (catgets (cat, SET_PROMPT_LOC, MSG_WILLINSTALLTO, MSG_WILLINSTALLTO_STR));
    gotoxy (5, 14);
    cputs (&destdir[2]);
      
    gotoxy (5, 16);
    s = catgets (cat, SET_PROMPT_LOC, MSG_INSTALLDIROK, MSG_INSTALLDIROK_STR);
    ch = select_yn (s, yes, no, NULL, NULL);
  } while (ch);

  /* Make sure destination directory exists (or create if not) */
  createdestpath(&destdir[2]);

  /* open the log file, if user wants it */
  if (wantlog)
  {
    if ((i = openlog(&destdir[2], "INSTALL.LOG")) != 0)
    {
      repaint_empty();
      gotoxy (5, 10);
      cputs (catgets (cat, SET_PROMPT_LOC, MSG_WILLINSTALLTO, MSG_WILLINSTALLTO_STR));
      gotoxy (5, 11);
      cputs (&destdir[2]);
      gotoxy (5, 13);
      fprintf(stderr, catgets(cat, SET_ERRORS, MSG_ERRCREATELOG, MSG_ERRCREATELOG_STR), i);
      pause();
    }
    /* note: if log is not opened, then calls to log immediately 
       return, so if (wantlog) log(...) wrapper is not needed for calls to log() */
    log("<install ver=\"%s\" logformat=\"1.0\" >\n", INSTALL_VERSION);
    log("<source path=\"%s\" />\n", &fromdir[2]);
    log("<dest path=\"%s\" />\n\n", &destdir[2]);
  }

  /* Ask to install every disk set */

  log("<installsets>\n");
  for (i = 0; i < dat_count; i++)
    {
      repaint_empty();
      gotoxy (2, 5);
      s = catgets (cat, SET_PKG_GENERAL, MSG_DISKSET, MSG_DISKSET_STR);
      cputs (s);
      cputs (dat_ary[i].name);
      log("<diskset name=\"%s\" ", dat_ary[i].name);

      /* create the txt file name */

      gotoxy (2, 10);
      cat_file (dat_ary[i].name, 10 /* no. lines */);

      gotoxy (2, 6);
      switch (dat_ary[i].rank)
	{
	case 'Y':
	case 'y':
	  s = catgets (cat, SET_PKG_NEED, MSG_REQUIRED, MSG_REQUIRED_STR);
	  cputs (s);
        log("choice=\"y\" />\n");
	  pause();
	  break;

	case 'N':
	case 'n':
	  s = catgets (cat, SET_PKG_NEED, MSG_SKIPPED, MSG_SKIPPED_STR);
	  cputs (s);
        log("choice=\"n\" />\n");
	  /* don't need to pause for this */
	  break;

	default:
	  s = catgets (cat, SET_PKG_NEED, MSG_OPTIONAL, MSG_OPTIONAL_STR);
	  cputs (s);

	  s = catgets (cat, SET_PROMPT_YN, MSG_INSTALLSETYN, MSG_INSTALLSETYN_STR);
	  ch = select_yn (s, yes, no, NULL, NULL);

	  switch (ch)
	    {
	    case 0:
	      dat_ary[i].rank = 'y';
            log("choice=\"y\" />\n");
	      break;

	    default:
	      dat_ary[i].rank = 'n';
            log("choice=\"n\" />\n");
	      break;
	    } /* switch ch */
	  break;
	} /* switch rank */
    } /* for i */
  log("</installsets>\n\n");

  /* Now install the selected disk sets */

  ret.errors = 0;
  ret.warnings = 0;

  for (i = 0; i < dat_count; i++)
    {
      switch (dat_ary[i].rank)
	{
	case 'Y':
	case 'y':
	  this = set_install (dat_ary[i].name, &fromdir[2], &destdir[2]);
	  ret.errors += this.errors;
	  ret.warnings += this.warnings;
	  break;
	} /* switch */
    } /* for i */


  /* close the log file, if user wanted it */
  log("</install>\n");
  closelog();

  /* Done */
  return (ret);
}
Example #22
0
void	dotranslate(char *from, char *topath)
{
	char	frompath[128],fromname[14];
	char	to[128],toname[14];
	char	*nptr;
	char	ans;

	char	buf[256];

	int	handle;
	FILE	*infile;

	int	doad;


	if (!split(from,frompath,fromname))
	{
		fprintf(stderr,"Couldn't parse filename %s.\n",from);
		return;
	}

	ans=0;

	nptr=fromname+strlen(fromname)-1;     	// lose the extension
	while (nptr>fromname)
		if (*nptr=='.')
		{
			*nptr=0;
			break;
		}
		else
			nptr--;


	if (!fiadordoad(topath,&doad,to,toname))
	{
		fprintf(stderr,"Can't access %s\n",topath);
		return;
	}
	else
	if (!doad)
	{
		dos2ti(fromname,toname);		// get 10-char name
		dochop(toname);
		strcat(toname,ext);
//		strcpy(fromname,toname);		// copy
//		ti2dos(fromname,toname);		// make DOS name
	}
	else
	{
		dos2ti(fromname,toname);		// get 10-char name
		dochop(toname);
		strcat(toname,ext);
		strcpy(fromname,toname);
	}

	strcpy(to,topath);
	strcat(to,toname);

	    while ((!overwrite) && tiexists(to) && ans!='O' && ans!='S')
	    {
		    fprintf(stderr,"File %s exists.  (O)verwrite, (R)ename, or (S)kip? ",to);
		    buf[0]=4;
		    cgets(buf);
                    fprintf(stderr,"\n");
		    ans=toupper(*(buf+2));
		    if (ans=='R')
		    {
			    fprintf(stderr,"Enter new filename in the form %s:  ",toname);
			    buf[0]=14;
			    cgets(buf);
			    fprintf(stderr,"\n");

			    strcpy(toname,buf+2);
			    strcpy(to,topath);
			    strcat(to,toname);
		    }
	    }


	if (ans!='S')
	{
		if ((infile=openbufferread(from))==NULL)
//		if (!openfoad(from, &handle))
		{
		    if (!ignore)
			fprintf(stderr,"File %s does not exist (?), skipping.\n",from);
		}
		else
		{
		    {
			if (!createti(to,type,reclen,&handle))
			{
			    fprintf(stderr,"Could not create %s !\n",to);
			    tierror(to);
			}
			else
			{
			    if (verbose)
				fprintf(stderr,"Converting %s to %s\n",from,to);

			    while (!feof(infile))
			    {
				getstring(buf,reclen,infile,!(type&F_VARIABLE),
					(type&F_INTERNAL) ? 0 : 0x20);
				if (chop)
				    dochop(buf);
				if (expandtabs)
				    doexpand(buf);

				if (!writeti(handle,buf,strlen(buf)))
				{
				    fprintf(stderr,"\tWrite error on %s !\n",to);
				    break;
				}
			    }
			    closeti(handle);
			}
		    }
		    closebufferread(infile);
		}
	}
}
int main(int argc, char *argv[])
{
   char cad[80];
   char destin[4096];
   int i;
   
   clrscr();
   textbackground(BLUE);
   textcolor(YELLOW);
   clrscr();
   getch();
   window(2,2,77,22);
   textbackground(RED);
   textcolor(LIGHTBLUE);
   clrscr();
   gotoxy(1,3); cprintf("Prueba");
   getch();
   window(3,3,76,21);
   textbackground(LIGHTBLUE);
   textcolor(CYAN);
   clrscr();
   gotoxy(1,3); cputs("Otra prueba");
   for(i = 0; i < 100; i++) cputs("111");
   highvideo();
   for(i = 0; i < 100; i++) cputs("222");
   lowvideo();
   for(i = 0; i < 100; i++) cputs("333");
   highvideo();
   for(i = 0; i < 100; i++) cputs("444");
   lowvideo();
   for(i = 0; i < 100; i++) cputs("555");
   highvideo();
   for(i = 0; i < 100; i++) cputs("666");
   getch();
   gotoxy(10, 12); cputs("aqui");
   getch();
   delline();
   getch();
   gotoxy(10, 1); cputs("aqui");
   getch();
   delline();
   getch();
   gotoxy(10, 15); cputs("aqui");
   getch();
   delline();
   getch();
   normvideo();
   for(i = 0; i < 500; i++) putch('*');
   getch();
   gotoxy(10, 4); cputs("aqui");
   getch();
   insline();
   cputs("insertada");
   getch();
   gotoxy(1, 7);
   cputs("Leer una cadena: ");
   cad[0]=10;
   cgets(cad);
   gotoxy(1, 8);
   cprintf("caracteres leidos: %d, cadena %s #relleno relleno relleno "
	   "relleno###########################", (int)cad[1], &cad[2]);
   clreol();
   getch();
   strcpy(cad, getpass("clave: ")); 
   cprintf("clave leida: %s", cad);
   getch();
   gettext(2, 2, 74, 19, destin);
   clrscr();
   getch();
   puttext(1, 1, 73, 18, destin);  
   getch();
   textbackground(BLUE);
   textcolor(WHITE);
   window(10,10,15,15);
   getch();
   normvideo();
   textcolor(WHITE);
   textbackground(BLACK);
   window(1,1,80,25);
   gotoxy(1,1);
   return 0;
}
Example #24
0
File: recv.c Project: eswartz/emul
int	main(void)
{
	int	ch;
	char	comm[256];
	struct	stat st;


	printf("RECV -- 99/4A ROM dump receiver by Edward Swartz.\n\n"
	       "Companion to TRANS on the 99/4A.\n\n");

	if (stat("MODULES",&st) || stat("ROMS",&st) || stat("MODULES.INF",&st))
	{
		printf("This program needs to be run from the directory where V9t9.EXE,\n"
		       "MODULES.INF, etc., are located.  (Use RECV.BAT from that directory.)\n");
		exit(1);
	}

	printf("In order to use this program, TRANS must be running on a\n"
	       "99/4A system connected to this PC by a serial cable.\n"
	       "It's best to start the 99/4A TRANS before running this program.\n\n"
	       "Press <Enter> to continue, or <Esc> to exit RECV:");
	do
		ch=getch();
	while	(ch!=13 && ch!=27);

	if (ch==27)
		exit(1);


	do
	{
		printf("\n\n\nEnter the DOS serial port you are using to connect\n"
		       "to the 99/4A.  Valid values are 1-4.\n\n: ");
		comm[0]=2;
		port=atoi(cgets(comm));
	}	while (port<1 || port>4);

	do
	{
		printf("\n\n\nEnter the IRQ of COM%d.  Typical value is %d.\n\n: ",
			port, ((port==1 || port==3) ? 4 : 3));
		comm[0]=2;
		irq=atoi(cgets(comm));
	}	while (irq<0 || irq>7);

	port--;			// fix port to 0-3

	do
	{
		printf("\n\n\nEnter the baud rate you used to initialize the RS232\n"
		       "in TRANS.  Valid baud rates are\n"
		       "\t110 300 600 1200 2400 4800 9600.\n\n: ");
		comm[0]=5;
		baudrate=atoi(cgets(comm));
	}	while (baudrate<110 || baudrate>9600);

	com_init(port,baudrate,irq);

	printf("\n\nRECV is ready to go.\n\n"
	       "Press a key at any time to abort.\n\n");
	while (!kbhit())
	{
//		ch=bioscom(_COM_RECEIVE,0,port);
		buf_init();
		if (!gs(comm))
		switch(comm[0])
		{
			case	'S':	ps("G");
					if (dump())
						Err();
					break;
			case	'M':    getbasename();
					ps("N");
					break;
			case	'N':	closemodule();
					ps("M");
					break;
			default:	Err();
					break;
		}
		else
			Err();
	}

	com_off();
	return	0;
}
Example #25
0
void record(long int puntos, char tablero) /* guarda de record */
{
	FILE *archivo;
	int cont, cont2, rest;
	char nombre[23], *nom, tablero_arch, cab, puntos_arch[11], buffer[LONGITUD + 1];

	if((archivo = fopen("packman.rcd", "r+")) == NULL) { /* abrir el archivo de records */
		puts ("No se puede abrir el archivo packman.rcd.");
		exit(0);
	}
	if((cab = getc(archivo)) == EOF) { /* byte de reconociemiento */
		puts ("Error al leer el archivo packman.rcd.");
		exit(0);
	}
	if(cab != 'D') { /* verificar archivo */
		puts ("Error al verificar el archivo packman.rcd.");
		exit(0);
	}
	for(cont = 0; cont < 10; cont++) {
		if(fread(nombre, 1, 22, archivo) != 22) { /* leer y descartar el nombre */
			puts ("Error leyendo el archivo packman.rcd.");
			exit(0);
		}
		if(fread(puntos_arch, 1, 10, archivo) != 10) { /* leer puntos */
			puts ("Error leyendo el archivo packman.rcd.");
			exit(0);
		}
		puntos_arch[10] = '\0';
		if(atol(puntos_arch) <= puntos) { /* comparar */
			/* guardar los dem s records en memoria para desplazarlos */
			fseek(archivo, (cont * 22) + (cont * 10) + (cont * 1) + 1, SEEK_SET);

			if(fread(buffer, (LONGITUD - ftell(archivo)) - ULTIMO_RCD, 1, archivo) != 1) {
				puts ("Error al intentar leer el archivo packman.rcd.");
				exit(0);
			}
			/* escribir el nuevo record en el lugar correcto */
			clrscr();
			textcolor(CYAN);
			gotoxy(1, 1);
			cprintf("Nombre:");
			textbackground(BLUE);
			textcolor(YELLOW);
			gotoxy(8, 1);
			cprintf("                      "); /* fondo */
			nombre[0] = 23; /* maximo 22 caracteres */
			gotoxy(8, 1);
			nom = cgets(nombre);
			fseek(archivo, (cont * 22) + (cont * 10) + cont + 1, SEEK_SET); /* llegar al lugar correcto */
			*(nom + 22) = '\0';
			rest = fprintf(archivo, "%s", nom);
			for(cont2 = 0; cont2 < 22 - rest; cont2++) putc(' ', archivo); /* espacios */
			rest = fprintf(archivo, "%ld", puntos);
			for(cont2 = 0; cont2 < 10 - rest; cont2++) putc(' ', archivo); /* espacios */
			fprintf(archivo, "%c", tablero + 1);
			/* escribir el resto de records */
			fseek(archivo, ((cont + 1) * 22) + ((cont + 1) * 10) + (cont + 1) + 1, SEEK_SET);
			buffer[LONGITUD + 1] = '\0';
			fwrite(buffer, 1, (LONGITUD - ftell(archivo)) - ULTIMO_RCD, archivo);
			break;
		} /* if(... */
		if(fread(&tablero_arch, 1, 1, archivo) != 1) { /* leer y descartar el tablero */
			puts ("Error leyendo el archivo packman.rcd.");
			exit(0);
		}
	} /* for(... */
	fclose(archivo);
	textbackground(BLACK);
}
Example #26
0
void main( void )
{
    int errFlag[NUMFUNC];
    char *funcName[] = { "cgets()",
                         "cprintf()",
                         "cputs()",
                         "getche()",
                         "getch()",
                         "kbhit()",
                         "putch()",
                         "ungetch()",
                         "cscanf()" };
    char buffer[83], str1[80], str2[80];
    int num1, num2;
    double fnum1;

    buffer[0] = 11;
    dispStr( "Start of cgets()...\r\n" );
    sprintf( str1, "Note: buffer[0] = %d.\r\n", buffer[0] );
    dispStr( str1 );
    dispStr( "Type the following (no quotes): \"12345\"\r\n" );
    cgets( buffer );
    sprintf( str1, "\r\nCharacter count = %d.\r\n", buffer[1] );
    dispStr( str1 );
    dispStr( "\r\nVerify: input string " );
    dispStr( "was (between the arrows):\r\n" );
    sprintf( str1, "-->%s<--\r\n", &buffer[2] );
    dispStr( str1 );
    dispStr( "Note: there shouldn't be any CR/LF contained in the string.\r\n" );
    errFlag[0] = strcmp( &buffer[2], "12345" ) != 0 ? TRUE : FALSE;
    dispStr( "Type the following (no quotes): \"123456789012345\"\r\n" );
    dispStr( "Note: only the first 10 characters should be allowed.\r\n" );
    cgets( buffer );
    sprintf( str1, "\r\nCharacter count = %d.\r\n", buffer[1] );
    dispStr( str1 );
    dispStr( "\r\nVerify: input string (first 10 characters) " );
    dispStr( "was (between the arrows):\r\n" );
    sprintf( str1, "-->%s<--\r\n", &buffer[2] );
    dispStr( str1 );
    dispStr( "Note: there shouldn't be any CR/LF contained in the string.\r\n" );
    if( errFlag[0] == FALSE ) {
        errFlag[0] = strcmp( &buffer[2], "1234567890" ) != 0 ? TRUE : FALSE;
    }
    dispStr( "Type the following: \"\" (just press <Enter>)\r\n" );
    cgets( buffer );
    sprintf( str1, "\r\nCharacter count = %d.\r\n", buffer[1] );
    dispStr( str1 );
    dispStr( "\r\nVerify: input string " );
    dispStr( "was (between the arrows):\r\n" );
    sprintf( str1, "-->%s<--\r\n", &buffer[2] );
    dispStr( str1 );
    dispStr( "Note: there shouldn't be anything contained in the string.\r\n" );
    if( errFlag[0] == FALSE ) {
        errFlag[0] = strcmp( &buffer[2], "" ) != 0 ? TRUE : FALSE;
    }
    dispStr( "End of cgets() test. Press <Enter> to continue.\r\n" );
    wait();

    dispStr( "\r\nStart of cprintf()...\r\n" );
    dispStr( "Compare the following:\r\n" );
    dispStr( "-----------------------------------------\r\n" );
    dispStr( "|-Start-> Testing <-|\r\n" );
    dispStr( "                     |-> 12345.67 <-End-|\r\n" );
    dispStr( "-----------------------------------------\r\n" );
    dispStr( "with the following. " );
    dispStr( "If cprintf() is ok,\r\nthey should be identical:\r\n" );
    strcpy( buffer, "Testing" );
    fnum1 = 12345.666;
    dispStr( "-----------------------------------------\r\n" );
    cprintf( "|-Start-> %s <-|\n|-> %8.2lf <-End-|\n\r",buffer, fnum1);
    dispStr( "-----------------------------------------\r\n" );
    dispStr( "Note: there shouldn't be any blank lines in between.\r\n" );
    dispStr( "Does cprintf() seem to work properly (y/n) ?" );
    *buffer = oneLetter();
    errFlag[1] = *(strlwr(buffer)) == 'y' ? FALSE: TRUE;
    dispStr( "End of cprintf() test. Press <Enter> to continue.\r\n" );
    wait();

    dispStr( "\r\nStart of cputs()...\r\n" );
    dispStr( "You should see \"|-->Testing<--|\" on next line:\r\n" );
    strcpy( buffer, "|-->" );
    cputs( buffer );
    strcpy( buffer, "Testing" );
    cputs( buffer );
    strcpy( buffer, "<--" );
    cputs( buffer );
    dispStr( "|\r\nDoes cputs() seem to work properly (y/n) ?" );
    *buffer = oneLetter();
    errFlag[2] = *(strlwr(buffer)) == 'y' ? FALSE: TRUE;
    dispStr( "End of cputs() test. Press <Enter> to continue.\r\n" );
    wait();

    dispStr( "\r\nStart of getche()...\r\n" );
    dispStr( "Press the key 'a':\r\n" );
    num1 = getche();
    dispStr( "\r\nthe character should have been echoed back.\r\n" );
    sprintf( buffer, "Check: you pressed ->%c<- (value=%d)\r\n", num1, num1 );
    dispStr( buffer );
    errFlag[3] = num1 != 'a' ? TRUE : FALSE;
    dispStr( "End of getche() test. Press <Enter> to continue.\r\n" );
    wait();

    dispStr( "\r\nStart of getch()...\r\n" );
    dispStr( "Press the key 'b':\r\n" );
    num1 = getch();
    dispStr( "\r\nNothing should have been echoed back.\r\n" );
    sprintf( buffer, "Check: you pressed ->%c<- (value=%d)\r\n", num1, num1 );
    dispStr( buffer );
    errFlag[4] = num1 != 'b' ? TRUE : FALSE;
    dispStr( "End of getch() test. Press <Enter> to continue.\r\n" );
    wait();

    dispStr( "\r\nStart of kbhit()...\r\n" );
    dispStr( "Waiting for user to press the key 'c' (looping):\r\n" );
    for( ; !kbhit(); );
    num1 = getch();
    dispStr( "getch() was used to obtain the character pressed.\r\n" );
    sprintf( buffer, "Check: you pressed ->%c<- (value=%d).\r\n", num1, num1 );
    dispStr( buffer );
    errFlag[5] = num1 != 'c' ? TRUE : FALSE;
    dispStr( "End of kbhit() test. Press <Enter> to continue.\r\n" );
    wait();

    dispStr( "\r\nStart of putch()...\r\n" );
    dispStr( "You should see:\r\n--\r\nH\r\n i\r\n--\r\nin the next four lines:\r\n" );
    dispStr( "--\r\n");
    num1 = 'H';
    num2 = 'i';
    putch( num1 );
    putch( '\n' );
    putch( num2 );
    putch( '\r' );
    putch( '\n' );
    dispStr( "--\r\n");
    dispStr( "Does putch() seem to work properly (y/n) ?" );
    *buffer = oneLetter();
    errFlag[6] = *(strlwr(buffer)) == 'y' ? FALSE: TRUE;
    dispStr( "End of putch() test. Press <Enter> to continue.\r\n" );
    wait();

    dispStr( "\r\nStart of ungetch()...\r\n" );
    dispStr( "Note: getch() will be used to get " );
    dispStr( "a character from the console.\r\n" );
    dispStr( "      Ignore this test if getch() is disfunctional.\r\n" );
    dispStr( "Waiting for user to press the key 'd':\r\n" );
    num1 = getch();
    sprintf( buffer, "Received the key ->%c<-\r\n",num1 );
    dispStr( buffer );
    num2 = ungetch( num1 );
    sprintf( buffer, "The character ->%c<- has been ungetch()'ed.\r\n", num1 );
    dispStr( buffer );
    dispStr( "Now, the character will once again be obtained using ");
    dispStr( "getch().\r\n" );
    num2 = getch();
    sprintf( buffer, "The character above ->%c<- was the one ", num2 );
    dispStr( buffer );
    dispStr( "being pushed back.\r\n" );
    if( num1 != num2 || num1 != 'd' ) {
        errFlag[7] = TRUE;
    } else {
        errFlag[7] = FALSE;
    }
    dispStr( "End of ungetch() test. Press <Enter> to continue.\r\n" );
    wait();

    dispStr( "\r\nStart of cscanf()...\r\n" );
    dispStr( "Input the following: 'test1 test2 1234 1.45'\r\n" );
    cscanf( "%s %s %d %lf", str1, str2, &num1, &fnum1 );
    getch();    // Discard the ending character that's left over
    dispStr( "\r\nThis is what you entered:\r\n" );
    sprintf( buffer, "\"%s, %s, %d, %4.2lf\"\r\n", str1, str2, num1, fnum1 );
    dispStr( buffer );
    if( strcmp( str1, "test1" ) != 0 || strcmp( str2, "test2" ) != 0 ||
        num1 != 1234 || fnum1 != 1.45 ) {
        errFlag[8] = TRUE;
    } else {
        errFlag[8] = FALSE;
    }
    dispStr( "End of cscanf() test. Press <Enter> to continue.\r\n" );
    wait();

    dispStr( "End of all tests.\r\n\r\n" );
    for( num1 = 0, num2 = FALSE; num1 < NUMFUNC; ++num1 ) {
        if( errFlag[num1] == TRUE ) {
            sprintf( buffer, "%s\r\n", funcName[num1] );
            dispStr( buffer );
            num2 = TRUE;
        }
    }
    dispStr( "\r\n" );
    if( num2 == TRUE ) {
        dispStr( "This program has found unexpected result(s) when testing" );
        dispStr( "\r\nthe above function(s). Reasons could be that the\r\n" );
        dispStr( "function(s) being used in the test(s) might have" );
        dispStr( " problems.\r\n" );
    } else {
        dispStr( "All the functions seem to pass the test!\r\n" );
    }
}
Example #27
0
char * 		 _RTL_FUNC _cgets(char *p)
{
    return cgets(p);
}
Example #28
0
/* Override fgets() in newlib with a version that does line editing */
__weak char *fgets(char *s, int bufsize, void *f) {
    cgets(s, bufsize);
    return s;
}
Example #29
0
int
main(void)
{
    int status;
    char line[128];
    alarm_t *alarm, **last, *next;
    pthread_t thread;

    if ((status = pthread_create(&thread, NULL, alarm_thread, NULL)) != 0) {
        cprintf("pthread_create: %s\n", strerror(status));
        exit(EXIT_FAILURE);
    }

    for (;;) {
        cprintf("Alarm> ");
        if (!cgets(line, sizeof(line)))
            exit(0);
        if (strlen(line) <= 1)
            continue;

        if (!(alarm = (alarm_t *) malloc(sizeof(alarm_t)))) {
            perror("malloc");
            exit(EXIT_FAILURE);
        }

        // Parse input line into seconds (%d) and a message (%64[^\n]),
        // consisting of up to 64 characters separated from the seconds by
        // whitespace.
        if (sscanf(line, "%d %64[^\n]", &alarm->seconds, alarm->message) < 2) {
            cprintf("Bad command\n");
            free(alarm);
        } else {
            if ((status = pthread_mutex_lock(&alarm_mutex)) != 0) {
                cprintf("pthread_mutex_lock: %s\n", strerror(status));
                exit(EXIT_FAILURE);
            }
            alarm->time = time(NULL) + alarm->seconds;

            // Insert the new alarm into the list of alarms, sorted by
            // expiration time.
            last = &alarm_list;
            next = *last;
            while (next) {
                if (next->time >= alarm->time) {
                    alarm->link = next;
                    *last = alarm;
                    break;
                }
                last = &next->link;
                next = next->link;
            }
            // If we reached the end of the list, insert the new alarm there.
            // ("next" is NULL, and "last" points to the link field of the
            // last item, or to the list header.
            if (!next) {
                *last = alarm;
                alarm->link = NULL;
            }

            //cprintf("[list: ");
            //for (next = alarm_list; next; next = next->link)
            //    cprintf("%d(%d)[\"%s\"] ", next->time, 
            //            next->time - time(NULL), next->message);
            //cprintf("]\n");

            if ((status = pthread_mutex_unlock(&alarm_mutex)) != 0) {
                cprintf("pthread_mutex_unlock: %s\n", strerror(status));
                exit(EXIT_FAILURE);
            }
        }
    }

    return 0;
}