📄 client_assist.c
字号:
#include <sys/ipc.h>#include <sys/mman.h>#include <sys/sem.h>#include <unistd.h>#include <sys/types.h>#include <signal.h>#include <stdio.h>#include <stddef.h>#include "../include/stddef.h"#include "../include/structs.h"#include "../include/tools.h"#include "../include/clientlib.h"SHM *shm;//void init_semaphore_struct(struct sembuf *sem,int semnum,//int semop,int semflg)//{ /* ........ */// sem->sem_num=semnum;// sem->sem_op=semop;// sem->sem_flg=semflg;//}/*int getInput(USER *user){ char *s; char c; char *p; int i = 0; p = user->name; while(1){ system("clear"); printf("Name :"); while(1){ if( ((c = getchar()) != '\n') && ((p - user->name) < MAX_SIZE) ){ *p ++ = c; continue; } break; } *p = '\0'; s = getpass("Password:"); p = user->pwd; while(1){ if( i < strlen(s) && ((p - user->pwd) < MAX_SIZE)){ *(p + i) = *(s + i); i ++; continue; } break; } *(p + i + 1) = '\0'; break; } printf("getinput() is over ... \n"); return OK;};*/int getInput(USER *user){ system("clear"); printf("Name : "); scanf("%s" , user->name); strcpy(user->pwd , getpass("Passwd :")); getchar(); return OK;};int readFile(char *guibuf){ FILE *fp; char c; int i = 0; fp = fopen(GUIFILE , "r"); if(!fp){ printf("file error!\n"); return EFILE; } while((c = fgetc(fp)) != EOF){ *(guibuf + i) = c; i ++; } *(guibuf + i + 1) = '\0'; fclose(fp); return OK;};int showGUI(char *guibuf){ printf("%s\n" , guibuf); return OK;};int getChoice(char *oper){ char *s = oper; char c; printf("please intput your choice : "); while(1){ c = getchar(); if( c != '\n' && ((s - oper) < OPER_SIZE)){ *s ++ = c; continue; }else{ if(c == '\n'){ break; } else { continue; } } } *s = '\0'; return OK;};int getInfo(char *oper , int index){ if(strcmp(oper , "query") == 0){ _query(index); }if(strcmp(oper , "changepwd") == 0){ _changepwd(index); }if(strcmp(oper , "save") == 0){ _save(index); //getchar(); }if(strcmp(oper , "transfer") == 0){ _trans(index); }if(strcmp(oper , "withdraw") == 0){ _draw(index); }if(strcmp(oper , "add")== 0){ _adduser(index); } return OK; };int getStr(char *str , int max){ char *s; char c; int i = 0; s = str; while(1){ c = getchar(); if(c != '\n' && i < max - 1){ *s ++ = c; continue; }else{ if(c == '\n')break; else continue; } *s = '\0'; } return OK;};int execute(int index , char *oper){ union sigval mysigval; if(strcmp(oper , "quit") == 0 || strcmp(oper , "exit") == 0){ freeSHM(index); exit(0); } getInfo(oper , index);// get user's input // send sig to server , catch with the index of swap_arr mysigval.sival_int = index; if(sigqueue((shm->swap_arr)[index].swap.spid,SIGRQST,mysigval)==-1){ printf("send error\n"); exit(1); } printf("sended...\n"); return OK; };int showResult(char *oper , int index){ if(strcmp(oper , "save") == 0){ save_(index); } if(strcmp(oper , "transfer") == 0){ trans_(index); } if(strcmp(oper , "changepwd") == 0){ changepwd_(index); } if(strcmp(oper , "query") == 0){ query_(index); } if(strcmp(oper , "add") == 0){ adduser_(index); } if(strcmp(oper , "withdraw") == 0) { draw_(index); } };int identify(USER *user){ USER usr; FILE *fp; if( (fp = fopen(PWDFILE , "r")) == NULL){ printf("pwdfile open error....\n"); exit(0); } while(fread(&usr, sizeof(USER), 1, fp)){ if(strcmp(usr.name , user->name) == 0){ if(strcmp(usr.pwd , user->pwd) == 0) return OK; else{ return EPWD; } } } return ENAME;};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -