Ejemplo n.º 1
0
void formatcells(void)
/* Prompts the user for a selected format and range of cells */
{
 int col, row, col1, col2, row1, row2, temp, newformat = 0;

 writeprompt(MSGCELL1);
 if (!getcell(&col1, &row1))
  return;
 writeprompt(MSGCELL2);
 if (!getcell(&col2, &row2))
  return;
 if ((col1 != col2) && (row1 != row2))
  errormsg(MSGDIFFCOLROW);
 else
 {
  if (col1 > col2)
   swap(&col1, &col2);
  if (row1 > row2)
   swap(&row1, &row2);
  if (!getyesno(&temp, MSGRIGHTJUST))
   return;
  newformat += (temp == 'Y') * RJUSTIFY;
  if (!getyesno(&temp, MSGDOLLAR))
   return;
  newformat += (temp == 'Y') * DOLLAR;
  if (!getyesno(&temp, MSGCOMMAS))
   return;
  newformat += (temp == 'Y') * COMMAS;
  if (newformat & DOLLAR)
   newformat += 2;
  else
  {
   writeprompt(MSGPLACES);
   if (!getint(&temp, 0, MAXPLACES))
    return;
   newformat += temp;
  }
  for (col = col1; col <= col2; col++)
  {
   for (row = row1; row <= row2; row++)
   {
    format[col][row] = (format[col][row] & OVERWRITE) | newformat;
    if ((col >= leftcol) && (col <= rightcol) &&
     (row >= toprow) && (row <= bottomrow))
     displaycell(col, row, NOHIGHLIGHT, NOUPDATE);
   }
  }
 }
 changed = TRUE;
} /* formatcells */
Ejemplo n.º 2
0
void setcolwidth(int col)
/* Sets the new column width for a selected column */
{
 int width, row;

 writeprompt(MSGCOLWIDTH);
 if (!getint(&width, MINCOLWIDTH, MAXCOLWIDTH))
  return;
 colwidth[col] = width;
 setrightcol();
 if (rightcol < col)
 {
  rightcol = col;
  setleftcol();
  setrightcol();
 }
 for (row = 0; row <= lastrow; row++)
 {
  if ((cell[col][row] != NULL) && (cell[col][row]->attrib == TEXT))
   clearoflags(col + 1, row, NOUPDATE);
  else
   clearoflags(col, row, NOUPDATE);
  updateoflags(col, row, NOUPDATE);
 }
 displayscreen(NOUPDATE);
 changed = TRUE;
} /* setcolwidth */
Ejemplo n.º 3
0
int main(int argc, char **argv) {
	
	int waittime = -1;
	char inputbuffer[1024];
	char *newenviron[] = {NULL};
	char *newargv[MAX_ARGS];
	char *newcmd = NULL;
	if(argc > 1) {
		waittime = atoi(argv[1]); 
	}
	signal(SIGALRM,handler);
	writeprompt();
	while(1) {
		int numread = read(STDIN_FILENO,inputbuffer,1024);
		//test for reading in return
		//check for empty array/set null
		if(numread >= MAX_ARG_LENGTH) {
			perror("Length of arguments exceeed the limitation");
		}
		inputbuffer[numread] = '\0';
		parsecommand(inputbuffer,&newcmd,newargv);
		pid = fork();
		if(!pid) {
			execve(newcmd,newargv,newenviron); 
			perror("execve failed");
			_exit(0);
		}else if(pid <0) {
			perror("fork() failed");
			_exit(0);
		}else{
			if(waittime > 0) {
				alarm(waittime);
			}
			wait(pid);
			writeprompt();
		}
		free( newcmd);
	}
	
}
Ejemplo n.º 4
0
void gotocell()
/* Moves to a selected cell */
{
 writeprompt(MSGGOTO);
 if (!getcell(&curcol, &currow))
  return;
 leftcol = curcol;
 toprow = currow;
 setbottomrow();
 setrightcol();
 setleftcol();
 displayscreen(NOUPDATE);
} /* gotocell */
Ejemplo n.º 5
0
/* Prints a prompt and gets a yes or no answer - returns FALSE if ESC was
    pressed, TRUE if not. */
int getyesno(int *yesno, char *prompt)
{
    writeprompt(prompt);
    setcursor(shortcursor);
    do {
        *yesno = toupper(getkey());
        if (*yesno == ESC) {
            setcursor(nocursor);
            return(FALSE);
        }
    }
    while (strchr("YN", *yesno) == NULL);
    setcursor(nocursor);
    return(TRUE);
} /* getyesno */
Ejemplo n.º 6
0
void printsheet(void)
/* Prints a copy of the spreadsheet to a file or to the printer */
{
 char filename[MAXINPUT + 1], s[133], colstr[MAXCOLWIDTH + 1];
 FILE *file;
 int columns, counter1, counter2, counter3, col = 0, row, border, toppage,
  lcol, lrow, dummy, printed, oldlastcol;

 filename[0] = 0;
 writeprompt(MSGPRINT);
 if (!editstring(filename, "", MAXINPUT))
  return;
 if (filename[0] == 0)
  strcpy(filename, "PRN");
 if ((file = fopen(filename, "wt")) == NULL)
 {
  errormsg(MSGNOOPEN);
  return;
 }
 oldlastcol = lastcol;
 for (counter1 = 0; counter1 <= lastrow; counter1++)
 {
  for (counter2 = lastcol; counter2 < MAXCOLS; counter2++)
  {
   if (format[counter2][counter1] >= OVERWRITE)
    lastcol = counter2;
  }
 }
 if (!getyesno(&columns, MSGCOLUMNS))
  return;
 columns = (columns == 'Y') ? 131 : 79;
 if (!getyesno(&border, MSGBORDER))
  return;
 border = (border == 'Y');
 while (col <= lastcol)
 {
  row = 0;
  toppage = TRUE;
  lcol = pagecols(col, border, columns) + col;
  while (row <= lastrow)
  {
   lrow = pagerows(row, toppage, border) + row;
   printed = 0;
   if (toppage)
   {
    for (counter1 = 0; counter1 < TOPMARGIN; counter1++)
    {
     fprintf(file, "\n");
     printed++;
    }
   }
   for (counter1 = row; counter1 < lrow; counter1++)
   {
    if ((border) && (counter1 == row) && (toppage))
    {
     if ((col == 0) && (border))
      sprintf(s, "%*s", LEFTMARGIN, "");
     else
      s[0] = 0;
     for (counter3 = col; counter3 < lcol; counter3++)
     {
      centercolstring(counter3, colstr);
      strcat(s, colstr);
     }
     fprintf(file, "%s\n", s);
     printed++;
    }
    if ((col == 0) && (border))
     sprintf(s, "%-*d", LEFTMARGIN, counter1 + 1);
    else
     s[0] = 0;
    for (counter2 = col; counter2 < lcol; counter2++)
     strcat(s, cellstring(counter2, counter1, &dummy, FORMAT));
    fprintf(file, "%s\n", s);
    printed++;
   }
   row = lrow;
   toppage = FALSE;
   if (printed < 66)
    fprintf(file, "%c", FORMFEED);
  }
  col = lcol;
 }
 fclose(file);
 lastcol = oldlastcol;
} /* printsheet */
Ejemplo n.º 7
0
void savesheet(void)
/* Saves the current spreadsheet */
{
 char filename[MAXINPUT+1], eof = 26;
 int size, col, row, overwrite, file;
 CELLPTR cellptr;

 filename[0] = 0;
 writeprompt(MSGFILENAME);
 if (!editstring(filename, "", MAXINPUT))
  return;
 if (!access(filename, 0))
 {
  if (!getyesno(&overwrite, MSGOVERWRITE) || (overwrite == 'N'))
   return;
 }
 if ((file = open(filename, O_RDWR | O_CREAT | O_TRUNC | O_BINARY,
  S_IREAD | S_IWRITE)) == -1)
 {
  errormsg(MSGNOOPEN);
  return;
 }
 writef(1, 25, PROMPTCOLOR, 79, MSGSAVING);
 gotoxy(strlen(MSGSAVING) + 1, 25);
 write(file, name, strlen(name) + 1);
 write(file, &eof, 1);
 write(file, (char *)&lastcol, 2);
 write(file, (char *)&lastrow, 2);
 size = MAXCOLS;
 write(file, (char *)&size, 2);
 write(file, colwidth, sizeof(colwidth));
 for (row = 0; row <= lastrow; row++)
 {
  for (col = lastcol; col >= 0; col--)
  {
   if (cell[col][row] != NULL)
   {
    cellptr = cell[col][row];
    switch(cellptr->attrib)
    {
     case TEXT :
      size = strlen(cellptr->v.text) + 2;
      break;
     case VALUE :
      size = sizeof(double) + 1;
      break;
     case FORMULA :
      size = strlen(cellptr->v.f.formula) + 2 + sizeof(double);
      break;
    } /* switch */
    write(file, (char *)&col, 2);
    write(file, (char *)&row, 2);
    write(file, (char *)&format[col][row], 1);
    write(file, (char *)&size, 2);
    write(file, (char *)cellptr, size);
   }
  }
 }
 close(file);
 writef(1, 25, WHITE, strlen(MSGSAVING), "");
 gotoxy(1, 25);
 changed = FALSE;
} /* savesheet */
Ejemplo n.º 8
0
void loadsheet(char *filename)
/* Loads a new spreadsheet */
{
 int size, allocated, reallastcol = 0, reallastrow = 0, file;
 char check[81];

 if (filename[0] == 0)
 {
  writeprompt(MSGFILENAME);
  if (!editstring(filename, "", MAXINPUT))
   return;
 }
 if (access(filename, 0))
 {
  errormsg(MSGNOEXIST);
  return;
 }
 if ((file = open(filename, O_RDWR | O_BINARY)) == -1)
 {
  errormsg(MSGNOOPEN);
  return;
 }
 read(file, check, strlen(name) + 1);
 if (strcmp(check, name) != 0)
 {
  errormsg(MSGNOTURBOCALC);
  close(file);
  return;
 }
 writef(1, 25, PROMPTCOLOR, 79, MSGLOADING);
 gotoxy(strlen(MSGLOADING) + 1, 25);
 clearsheet();
 read(file, (char *)&size, 1);
 read(file, (char *)&lastcol, 2);
 read(file, (char *)&lastrow, 2);
 read(file, (char *)&size, 2);
 read(file, colwidth, sizeof(colwidth));
 do
 {
  if (read(file, (char *)&curcol, 2) <= 0)
   break;
  read(file, (char *)&currow, 2);
  read(file, &format[curcol][currow], 1);
  read(file, (char *)&size, 2);
  read(file, (char *)&rec, size);
  switch (rec.attrib)
  {
   case TEXT :
    if ((allocated = alloctext(curcol, currow, rec.v.text)) == TRUE)
     setoflags(curcol, currow, NOUPDATE);
    break;
   case VALUE :
    allocated = allocvalue(curcol, currow, rec.v.value);
    break;
   case FORMULA :
    allocated = allocformula(curcol, currow, rec.v.f.formula, rec.v.f.fvalue);
    break;
  } /* switch */
  if (!allocated)
  {
   errormsg(MSGFILELOMEM);
   lastrow = reallastrow;
   lastcol = reallastcol;
   format[curcol][currow] = DEFAULTFORMAT;
   break;
  }
  else
  {
   if (curcol > reallastcol)
    reallastcol = curcol;
   if (currow > reallastrow)
    reallastrow = currow;
  }
 }
 while (TRUE);
 writef(1, 25, WHITE, strlen(MSGLOADING), "");
 gotoxy(1, 25);
 printfreemem();
 close(file);
 curcol = currow = 0;
 setrightcol();
 displayscreen(NOUPDATE);
 changed = FALSE;
} /* loadsheet */