예제 #1
0
파일: util.c 프로젝트: McUsr/Index-2.0
void
yerror( int strIndex, const char *handler, const char *variable, int ourErrCode )
{
	char errL1[BUFSIZ];
	char errL2[BUFSIZ];
    int errL = 2 ;
    if (!hasError) {
        hasError = 1 ;
	    sprintf(errL1,(const char *)errstrings[strIndex] ,pname,handler, variable) ; 
        if ((strIndex != YICU_CONV_ERR ) && (strIndex != YICU_COLLATO_ERR ) 
                && (strIndex != YICU_CRECOLL_ERR ) && (strIndex != YICU_CNVFUTF8_ERR )
                && (strIndex != YICU_CNVPREUTF8_ERR ) ) {
	        sprintf(errL2,"%s: error number : %d, message: %s.",pname,errno,strerror(errno) ) ;
            errL = 1 ;
        }
        /* here is the place we call stuff if curses is inited */
        if (curses_active() ) {
            register int y,x ;
		    getyx(curscr, y, x);
	        mvaddstr(y++, 5, errL1);
            if (errL==2) {
	            mvaddstr(y++, 5, errL2);
            }
           prompt_char(y,5,"Hit any key to exit Index",NULL) ; 
            /* we take down curses here */
        }         
        finish(0) ; 
        fprintf(stderr,"%s\n",errL1) ;
        if ( errL == 2 ) {
            fprintf(stderr,"%s\n",errL2) ;
        }
        exit(ourErrCode ) ;
   }
}
예제 #2
0
파일: dbcreate.c 프로젝트: McUsr/Index-2.0
/*
 * create_db - execute an editor to allow the person to create the
 *         index definition file.

 * The rules for creating the name of the database file, and the provider
 * of the new name resides in the function newlabelFilename that resides in
 * newlabelFilename 
 */
void
create_db(void)
{
	int pid;

	char *editor;

	register int row;

	char *fname=NULL; 
    set_modes() ;
	/* Clear the screen and move to the top. */
	clear();
	move(0, 0);

	/* Print out the explanatory message.  */
	for (row = 0; message[row].m_line != NULL; row++)
		printw(message[row].m_line, message[row].m_arg);

	/* Give the user a chance to read it.  Wait till they
	 * type a carriage return before proceeding.  */
	prompt_char(++row, 0, "Type RETURN to continue: ", "\n\r");

	/* Use the editor the user prefers, or EDITOR if
	 * he doesn't have anything set.  */
	if ((editor = getenv("EDITOR")) == NULL)
		editor = EDITOR;
	/* get the label file name.  */
    fname = getFullLabelFileName() ;

	/* Go back to normal tty modes.  */
	reset_modes();

	/* Spawn a child process.  */
	if ((pid = fork()) < 0) {
        yerror(YFORK_PROC_ERR,"create_db",editor,YX_EXTERNAL_CAUSE ) ;
	}
	/* Execute the editor. */
	if (pid == 0) {
		reset_modes();
		execl(editor, editor, fname, NULL);
		perror(editor);
		exit(1);
	}
	/* Wait for the editor to finish.  */
	while (wait((int *)0) != pid) ;
    /* loose the reference to the filename */
    fname = NULL; 
	/* Set the tty modes up again.  */
	set_modes();
}
예제 #3
0
파일: screen.c 프로젝트: McUsr/Index-2.0
int
byebye(void)
{
    static const char exitPrompt[]="Really exit without saving? (y/n) ";
	register char c;

	register int x, y;

	/* If db is modified, then see if user really wants to  */
	/* quit without saving.                                 */
	if (dbmodified) {
		getyx(curscr, y, x);
		c = prompt_char(y, 0,exitPrompt , "YyNn");
		if ((c == 'n') || (c == 'N'))
			return 0;
		else
			return 1;
	}
	return 1;		/* Silently exit as dbase wasn't modified    */
	/* reset_modes(); exit(0); takes place in finish()/main() */

}
예제 #4
0
파일: screen.c 프로젝트: McUsr/Index-2.0
 /*
    Returns whether we should save our changes or not.

    Edits an existing an entry. This routine is far to big, and handles
    everything, from movement between fields, and editing fields, even
    painting the screen.

 */
int
edit_entry(dbrecord * entry, const char *operationDesc, const char *entryDesc)
{
	int *len;
	int col0;
	wchar_t *line=NULL;
	char tbuf[MAXSCREENWIDTH];
	int code = 0;
	wchar_t ch;
	dbbuffer tmp;
	register int i, j, row, col;
    initHeading() ;
	/* Where is "column zero"? To right of longest field name.  */
	col0 = idx.idx_maxlen + 2;

	 clear();		/* Clear the screen.                            */
    initEntryLine() ;
    paintHeading(operationDesc) ;
	/* get max col TODO: change this when sigwhinch */
    /* first time: allocat wchar fulldbdir name
       fulldbdir is a static.*/
	for (row = STARTROW; row < (idx.idx_nlines+STARTROW); row++) { 
		/* print field names.                                   */
		mvaddwstr(row, 0, idx.idx_lines[row-STARTROW]);
	}
	/* Allocate some space in a temporary entry, and copy entry */
	/* to be edited into it.  This way they can abort the edit. */
	/* Here we need to allocate some extra space so we can edit */

	for (i = STARTROW; i < (idx.idx_nlines+STARTROW); i++) {
        int k = i-STARTROW ;
		if (entry->db_lens[k] == 0) {
			/* Allocate memory for this line.                   */
            size_t linelen = (MAXSCREENWIDTH * sizeof(wchar_t));
			tmp.db_lines[k] =
                 (wchar_t *) ymalloc(linelen,
                    "edit_entry","tmp.db_lines[k]" );
            memset(tmp.db_lines[k],0,linelen);
			tmp.db_lens[k] = 0;
		} else {
			/* Copy and print the line from the entry.          */
			tmp.db_lines[k] =
			    wcsFromUnicode_alloc((size_t *) & tmp.db_lens[k],
						 entry->db_lines[k],
						 (int32_t) entry->db_lens[k]);
			if (tmp.db_lines[k] == NULL) {
                yerror( YICU_CONV_ERR ,"edit_entry->wcsFromUnicode_alloc", "tmp.db_lines[k]", YX_EXTERNAL_CAUSE ) ;
			}
			/* reallocates more space to maximum linebuffer size. */
			tmp.db_lines[k] =
			    (wchar_t *) yrealloc(tmp.db_lines[k], (size_t)
						(MAXSCREENWIDTH * sizeof(wchar_t)),"edit_entry","tmp.db_lines[k]");
		}

		move(i, col0);
		clrtoeol();
		if (tmp.db_lens[k] > 0) {
			addwstr(tmp.db_lines[k]);
		}
	}			/* *could* have factored out the index code.              */
	col = col0;
	row = STARTROW;		/* row er hvilke rad i recorden (felt). */

	move(row, col);
	refresh();
	/* Editing entry. We provide basic EMACS-style cntrl chars. */
	while ((code = get_wch(&ch)) != EOF) {
		/* Get the current line and line length.                */
		line = tmp.db_lines[row-STARTROW];
		/* f.p. *len = &tmp.db_lens[row]; */
		len = &tmp.db_lens[row-STARTROW];
		switch (ch) {
		case CTRL('a'):	/* beginning of line            */
			col = col0;
			break;
		case KEY_LEFT:
		case CTRL('b'):	/* back character               */
			if (col > col0)
				col--;
			break;
		case CTRL('d'):	/* delete character             */
			if (col == (col0 + (int)wcslen(line))) {
				col--;
			} else if (*len) {
				/* Calculate position of character in string.   */
				int l = col - col0;

				/* Shuffle the string to the "left".            */
				while (l < *len) {
					line[l] = line[l + 1];
					l++;
				}
				*len -= 1;
				/* Delete the character on the screen.          */
				delch();
                if (col== (col0 + (int)wcslen(line)) ) {
                    --col ;
                }
			}

			break;
		case CTRL('e'):	/* end of line                  */
			col = col0 + *len;
			break;
		case KEY_RIGHT:
		case CTRL('f'):	/* forward character            */
			if ((col - col0) < *len)
				col++;
			break;
		case KEY_BACKSPACE:
		case CTRL('h'):	/* backspace delete             */
		case '\177':
			if (*len && ((col - 1) >= col0)) {
				/* Calculate position of character to delete.   */
				int l = col - col0 - 1;
				if (l < 0)
					break;
				/* Shuffle string "left".                        */
				while (l < *len) {
					line[l] = line[l + 1];
					l++;
				}

				*len -= 1;

				/* Delete the character from the screen.        */
				move(row, --col);
				delch();
			}
			break;
		case CTRL('k'):	/* kill line                    */
			if (len) {
                
			    int l = col - col0;

				line[l] = (wchar_t) '\0';
				*len = l;

				clrtoeol();
			}
			break;
		case CTRL('l'):	/* redraw screen                */
			wrefresh(curscr);
			break;
		case KEY_DOWN:
		case CTRL('n'):	/* next line                    */
			/* Wrap around to the top if necessary.             */
			if (++row >= (idx.idx_nlines+STARTROW))
				row = STARTROW; 
			/* If nothing in this column, move to nearest       */
			/* non-empty column.                                */
			if ((col - col0) > tmp.db_lens[row-STARTROW])
				col = col0 + tmp.db_lens[row-STARTROW];
			line[*len] = (wchar_t) '\0';
			break;
		case KEY_UP:
		case CTRL('p'):	/* previous line                */
			/* Wrap around if necessary.                        */
			if (--row < STARTROW)
				row = (idx.idx_nlines+STARTROW) - 1;

			/* If nothing in this column, move to nearest       */
			/* on-empty column.                                 */
			if ((col - col0) > tmp.db_lens[row-STARTROW])
				col = col0 + tmp.db_lens[row-STARTROW];
			line[*len] = (wchar_t) '\0';
			break;
		case CTRL('['):	/* save entry:  ESC or something...  */
			if (line[*len] != (wchar_t) '\0')
				line[*len] = (wchar_t) '\0';
			sprintf(tbuf, "Save %s entry in database (y/n)? ", entryDesc);
			ch = prompt_char(idx.idx_nlines + 2+ STARTROW, 0, tbuf, "yYnN");

			/* See what they said.                              */
			switch (ch) {
			case '\n':	/* never mind                       */
				move(idx.idx_nlines + 2, 0);
				clrtoeol();
				break;
			case 'Y':	/* save entry                       */
			case 'y':
				/* Copy the temporary entry into the real entry. */
				/* if there isn't anything to copy, then the entry db gets the value
				   NULL, and length 0 */
				for (i = 0; i < idx.idx_nlines; i++) {

					/* remove old contents in entry             */
					if (entry->db_lens[i] > 0) {
						free(entry->db_lines[i]);
						entry->db_lines[i] = NULL;
						entry->db_lens[i] = 0;
					} 
                    
                    if (tmp.db_lens[i] > 0) {
                        entry->db_lens[i]=tmp.db_lens[i] ;
						entry->db_lines[i] =
						    unicodeFromWcs_alloc((size_t *) &entry->db_lens[i],tmp.db_lines[i]);

					    if (entry->db_lines[i] == NULL) {
                            yerror( YICU_CONV_ERR ,"edit_entry->unicodeFromWcs_alloc", "entry->db_lines[i]", YX_EXTERNAL_CAUSE ) ;
                        }
                    } /* had a dangling else bug here ? */
					free(tmp.db_lines[i]);
                    tmp.db_lines[i] = NULL ;
				    tmp.db_lens[i] = 0;
				}
				return (1);
			case 'N':	/* don't save entry                 */
			case 'n':
				/* Free temporary memory.                       */
				for (i = 0; i < idx.idx_nlines; i++) {
					tmp.db_lens[i] = 0;
					free(tmp.db_lines[i]);
					tmp.db_lines[i] = NULL;
				}
				return (0);
			}
			break;
		case '\r':	/* return the string            */
		case '\n':	/* go to next line                  */
			/* Wrap around if necessary.                        */
			if (++row >= (idx.idx_nlines+STARTROW))
				row = STARTROW;
			col = col0;
			break;
		default:	/* something else                   */
			/* User's kill character: accepted to del line too. */
			if (ch == KEY_DL) {
				move(row, col0);
				clrtoeol();
				col = col0;

				*line = (wchar_t) '\0';
				*len = 0;
			} else if (code != KEY_CODE_YES) {
				/* If it's a printable character, insert it into */
				/* the string.                                  */
				if (iswctype(ch, wctype("print"))) {
					if (col == (COLS - 1)) {
						beep();
						break;
					}
					/* Calculate character position.            */
					i = col - col0;

					/* If necessary, move string * to "right"   */
					/* to insert the character.                 */
					if (i < *len) {
						for (j = *len; j >= i; j--)
							line[j + 1] = line[j];
					}

					line[i] = ch;
					*len += 1;
					col++;

					/* Insert the character on the screen.       */
					InsWch((chtype) ch);

				}
			}
			break;
		}

		/* Move to the current row/column.                       */
		move(row, col);
		refresh();
	}
	return (0);
}
void i2c_slave ()
{
   uint8_t i = prompt_char("#:");
   dev_ioctl(DEV_AVR_I2C, I2C_SLAVE_ADDR, i);
}