/* * Copyright (C) 2003 Wesley Oliveira, Aline Oliveira, Hudson Reis, * Husni Ali Husni. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2.1, * or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; see the file COPYING.LIB. If * not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include "globals.h" #ifndef MAXLINE #define MAXLINE 1024 #define MINLINE 256 #endif #if defined(SunOS) #include #else # if defined(__CYGWIN__) # include # else # if defined(__MINGW32__) # include //# include # else # include # endif # endif #endif char cobpri[MAXLINE], cobpro[MAXLINE]; struct cbl_stream { char path[MAXLINE]; FILE *fd; int handle; } cbl_stream[MAXLINE]; /* Prototypes */ cbl_t cbl_copy_file(char *entrada, char *saida); cbl_t cbl_rename_file(char *old, char *new); cbl_t cbl_delete_file(char *arquivo); cbl_t cbl_check_file_exist(char *arquivo); cbl_t cbl_move_file(char *origem,char *destino); void cbl_open_file(char *arquivo,char *access_mode, char *deny_mode, int file_handle, cbl_t *retorno); void cbl_create_file(char *arquivo, unsigned char *access_mode, unsigned char *deny_mode, char file_handle[5], cbl_t *retorno); cbl_t cbl_close_file(int file_handle); cbl_t cbl_flush_file(int file_handle); void cbl_read_file(int file_handle, int number_bytes, char *buffer_read, cbl_t *retorno); void cbl_write_file(int file_handle,int number_bytes,char *buffer_writed,cbl_t *retorno); /* Functions */ cbl_t cbl_copy_file(char *entrada, char *saida) { FILE *fd_in, *fd_out; int c,valor; if ( cbl_align(entrada) != 0 ) { return 1; } if( cbl_align(saida) != 0 ) { return 1; } if ( (valor=cbl_parm(entrada,saida)) == -2 ) { return 0; } if ( valor == 1 ) { return 1; } if ( (fd_in = fopen(cobpri,"rb")) == NULL ) { return 3; } else { if ( (fd_out=fopen(cobpro,"wb")) == NULL ) { fclose(fd_in); return 3; } } while ( (c = fgetc(fd_in)) != EOF ) { fputc(c,fd_out); } #ifdef __MSVCRT__ chmod(cobpro,0666); #else cbl_get_per(cobpro); #endif fclose(fd_in); fclose(fd_out); return 0; } cbl_t cbl_rename_file(char *old, char *new) { int valor; if ( cbl_align(old) != 0 ) { return 1; } if (cbl_align(new) != 0) { return 1; } valor = cbl_parm(old,new); if(valor == 1) { return valor; } if (rename(cobpri,cobpro) == 0) { return 0; } else { return 3; } } cbl_t cbl_delete_file(char *arquivo) { int valor; if ( cbl_align(arquivo) != 0 ) { return 1; } if ( (valor=cbl_parm(arquivo,""))== -2 ) { return 0; } if ( valor == 1 ) { return valor; } chdir(cobpri); if (remove(cobpri) != 0) { return 2; } return 0; } cbl_t cbl_check_file_exist(char *arquivo) { int valor; //DIR *dir; if (cbl_align(arquivo) != 0) { return 1; } valor = cbl_parm(arquivo,""); if ( opendir(cobpri) != NULL ) { return(-1); } if ( access(cobpri,F_OK) != 0 ) { return 1; } return 0; } cbl_t cbl_move_file(char *origem, char *destino) { int valor; if ( cbl_align(origem) != 0 ) { return 1; } if ( cbl_align(destino) != 0 ) { return 1; } valor = cbl_parm(origem,destino); if ( valor == 1 ) { return valor; } if (cbl_copy_file(cobpri,cobpro) == 0) { if (cbl_delete_file(cobpri) != 0) { return 5; } } else { return 3; } return 0; } void cbl_open_file(char *arquivo, char *access_mode, char *deny_mode,int file_handle, cbl_t *retorno) { register int i; int valor; cbl_align(arquivo); cbl_align(access_mode); cbl_align(deny_mode); valor=cbl_parm(arquivo,""); // if(valor == 1) { return valor; } walter if ( valor == 1 ) { *retorno = 1; return; } if ( !strcmp(access_mode,deny_mode) ) { *retorno = 1; return; } for ( i=1 ; i max_col) max_col = strlen(line); max_lines++; fgets(line, 1024, file); } fclose(file); file = fopen(narq, "r"); // Alloc memory to put text text = malloc( (sizeof(char) * ( max_col * max_lines )) + 128 ); *text = 0; memset(text, ' ', (sizeof(char) * ( max_col * max_lines )) + 128); fgets(line, 1024, file); p = 0; while ( !feof(file) ) { memcpy(text + p, line, strlen(line)); p += max_col; fgets(line, 1024, file); } fclose(file); // show the file fline = 0; fcol = 0; ncol = 80; if(ncol > max_col) ncol = max_col; show = 1; while(show) { p = 0; while( (fline + p) < max_lines && p < 24) { move(p, 0); pnt = ( (fline + p) * max_col ) + fcol; addnstr(text + pnt, ncol); p++; } move(0, 0); ca = getch(); switch(ca) { case 'i': case 'I': fline = 0; fcol = 0; break; case 'a': case 'A': if ( fline > 0 ) fline--; break; case 'z': case 'Z': if ( fline < (max_lines - 24) ) fline++; break; case ',': if ( fcol > 0 ) fcol--; break; case '.': if ( fcol < (max_col - 80) ) fcol++; break; case 'f': case 'F': show = 0; break; } } // Return to the application free(text); free(narq); return; }