/**************/ /* tiedleik.c */ /**************************************************************************** ** PROGRAM: tiedleik.c ** PURPOSE: DaDin tiedoston käsittely ja leikekirjan käsittely ****************************************************************************/ #include /* Tarvitaan kaikissa Windows C-ohjelmissa */ #include #include #include #include #include #include "dadsave.h" #include "mjonot.h" #include "filename.h" #include "clipboard.h" #include "dadsave.h" #include "listbox.h" #include "tiedleik.h" #include "language.h" tDaDClpOptions DaDOpt; /***************************************************************************/ int read_clp_options(const char *ininame) { char entry[30]="delxxx"; int i; DaDOpt.delbegin = GetPrivateProfileInt(DADCLP,"delbegin",0,ininame) != 0; DaDOpt.delblanks = GetPrivateProfileInt(DADCLP,"delblanks",0,ininame) != 0; DaDOpt.small = GetPrivateProfileInt(DADCLP,"small",0,ininame) != 0; DaDOpt.dublicate = GetPrivateProfileInt(DADCLP,"dublicate",0,ininame) != 0; GetPrivateProfileString(DADCLP,"comments","",N_S(DaDOpt.comments),ininame); GetPrivateProfileString(DADCLP,"separators","",N_S(DaDOpt.sep),ininame); muunna_C_symbolit(DaDOpt.comments); muunna_C_symbolit(DaDOpt.sep); for ( i=0; i= 0 ) continue; if ( ListBox_AddString(lhWnd,s) < 0 ) return -1; } return 0; } /***************************************************************************/ static char *data_to_text(HWND hWnd,int id,int all) { return listbox_to_text(hWnd,id,all,N_S(buf)); } /***************************************************************************/ int MyNew(FileType *File) { SendMessage(File->hWnd,WM_COMMAND,GET_WM_COMMAND_MPS(CM_EDIT_CLEAR_ALL,0,0)); return 0; } /***************************************************************************/ int MySave(FileType *File) { int count,n; static char *s; #if 1 static OFSTRUCT OfStruct; HFILE hFile = OpenFile(File->Name,&OfStruct,OF_CREATE); if ( hFile == HFILE_ERROR ) goto error; s = data_to_text(File->hWnd,File->id,1); count = strlen(s); n = _lwrite(hFile,s,count); _lclose(hFile); #else FILE *f = fopen(File->Name,"wb"); if ( f == NULL ) goto error; s = data_to_text(File->hWnd,File->id,1); count = strlen(s); n = fwrite(s,1,count,f); fclose(f); #endif if ( n == count ) return 0; error: MessageBox(File->hWnd,File->Name,T("Talletus epäonnistui"), MB_APPLMODAL | MB_OK | MB_ICONEXCLAMATION); return -1; } /***************************************************************************/ int MyRead(FileType *File) { int n = MyNew(File); #if 1 static OFSTRUCT OfStruct; HFILE hFile = OpenFile(File->Name,&OfStruct,OF_READ); if ( hFile == HFILE_ERROR ) goto error; n = _lread(hFile,N_S(buf)-1); _lclose(hFile); #else FILE *f = fopen(File->Name,"rb"); if ( f == NULL ) goto error; n = fread(buf,1,sizeof(buf)-1,f); fclose(f); #endif if ( n < 0 ) goto error; buf[n] = 0; text_to_data(File->hWnd,File->id,buf); return 0; error: MessageBox(File->hWnd,File->Name,T("Lukeminen epäonnistui"), MB_APPLMODAL | MB_OK | MB_ICONEXCLAMATION); return -1; } /***************************************************************************/ int clipboard_to_data(HWND hWnd,int id) { TextFromClipboard(hWnd,buf); return text_to_data(hWnd,id,buf); } /***************************************************************************/ int data_to_clipboard(HWND hWnd,int id) { char *text; text = data_to_text(hWnd,id,0); TextToClipboard(hWnd,text); return 0; } /***************************************************************************/ FileType File={ "", /* Tiedoston nimi, aluksi "" */ WTITLE, /* Ikkunan otsikko, jonka perään tied.nimi */ 1, /* Luetun funktion tyyppi, ks. szFilter */ "DaD (*.dad)\0*.dad\0Teksti (*.txt)\0*.txt\0Kaikki (*.*)\0*.*\0", 0, /* Onko tiedostoa muutettu. */ MySave, /* Osoitin talletusfunktioon */ MyRead, /* Osoitin lukufunktioon */ MyNew, /* Osoitin tiedon nollausfunktioon */ NULL, /* Osoitin varsinaiseen dataan. */ IDC_DADLIST /* Dataikkunan ID */ };