Changeset 1830 for trunk/packages/vizservers/pymolproxy/pymolproxy.c
- Timestamp:
- Jul 17, 2010, 1:54:59 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/pymolproxy/pymolproxy.c
r1814 r1830 57 57 #include <fcntl.h> 58 58 #include <getopt.h> 59 #include <net/if.h>60 #include <netinet/in.h>61 59 #include <poll.h> 62 #include <signal.h>63 60 #include <stdio.h> 64 61 #include <stdlib.h> 65 62 #include <string.h> 66 #include <sys/ioctl.h>67 #include <sys/select.h>68 #include <sys/socket.h>69 63 #include <sys/stat.h> 70 64 #include <sys/time.h> … … 102 96 103 97 static FILE *flog; 104 static int debug = 0;98 static int debug = FALSE; 105 99 static FILE *scriptFile; 106 static int savescript = 0;100 static int savescript = FALSE; 107 101 108 102 typedef struct Image { … … 1025 1019 const char *argv[]) 1026 1020 { 1027 const char * pdbdata, *name;1028 PymolProxy *proxyPtr = clientData;1029 int state = 1;1030 int i, defer = 0, push = 0, varg = 1;1021 const char *data, *name; 1022 char *allocated; 1023 PymolProxy *proxyPtr = clientData; 1024 int state, defer, push; 1031 1025 int nBytes; 1032 1033 if (proxyPtr == NULL) 1026 int i, j; 1027 1028 if (proxyPtr == NULL){ 1034 1029 return TCL_ERROR; 1035 clear_error(proxyPtr); 1036 pdbdata = name = NULL; /* Suppress compiler warning. */ 1037 nBytes = 0; /* Suppress compiler warning. */ 1038 for(i = 1; i < argc; i++) { 1039 if ( strcmp(argv[i],"-defer") == 0 ) 1040 defer = 1; 1041 else if (strcmp(argv[i],"-push") == 0) 1042 push = 1; 1043 else if (varg == 1) { 1044 nBytes = atoi(argv[i]); 1045 varg++; 1046 } else if (varg == 2) { 1047 name = argv[i]; 1048 varg++; 1049 } else if (varg == 3) { 1050 state = atoi( argv[i] ); 1051 varg++; 1030 } 1031 clear_error(proxyPtr); 1032 defer = push = FALSE; 1033 for(i = j = 1; i < argc; i++) { 1034 if (strcmp(argv[i],"-defer") == 0) { 1035 defer = TRUE; 1036 } else if (strcmp(argv[i],"-push") == 0) { 1037 push = TRUE; 1038 } else { 1039 if (j < i) { 1040 argv[j] = argv[i]; 1041 } 1042 j++; 1043 } 1044 } 1045 argc = j; 1046 if (argc < 4) { 1047 Tcl_AppendResult(interp, "wrong # arguments: should be \"", argv[0], 1048 " <data>|follows <model> <state> ?<nBytes>?\"", 1049 (char *)NULL); 1050 return TCL_ERROR; 1051 } 1052 data = argv[1]; 1053 name = argv[2]; 1054 if (Tcl_GetInt(interp, argv[3], &state) != TCL_OK) { 1055 return TCL_ERROR; 1056 } 1057 nBytes = -1; 1058 if (strcmp(data, "follows") == 0) { 1059 if (argc != 5) { 1060 Tcl_AppendResult(interp, "wrong # arguments: should be \"", argv[0], 1061 " follows <model> <state> <nBytes>\"", (char *)NULL); 1062 return TCL_ERROR; 1063 } 1064 if (Tcl_GetInt(interp, argv[4], &nBytes) != TCL_OK) { 1065 return TCL_ERROR; 1066 } 1067 if (nBytes < 0) { 1068 Tcl_AppendResult(interp, "bad value for # bytes \"", argv[4], 1069 "\"", (char *)NULL); 1070 return TCL_ERROR; 1052 1071 } 1053 1072 } … … 1061 1080 /* Does not invalidate cache? */ 1062 1081 1082 allocated = NULL; 1083 if (nBytes >= 0) { 1084 allocated = malloc(sizeof(char) * nBytes); 1085 if (allocated == NULL) { 1086 Tcl_AppendResult(interp, "can't allocate buffer for pdbdata.", 1087 (char *)NULL); 1088 return TCL_ERROR; 1089 } 1090 if (GetBytes(&proxyPtr->client, allocated, nBytes) != BUFFER_OK) { 1091 Tcl_AppendResult(interp, "can't read pdbdata from client.", 1092 (char *)NULL); 1093 free(allocated); 1094 return TCL_ERROR; 1095 } 1096 data = allocated; 1097 } else { 1098 nBytes = strlen(data); 1099 } 1063 1100 { 1064 1101 char fileName[200]; 1065 1102 FILE *f; 1066 char *data;1067 1103 ssize_t nWritten; 1068 1104 1069 data = malloc(sizeof(char) * nBytes); 1070 if (data == NULL) { 1071 trace("can't allocate %d bytes for \"pdbdata\" buffer", nBytes); 1072 return TCL_ERROR; 1073 } 1074 if (GetBytes(&proxyPtr->client, data, nBytes) != BUFFER_OK) { 1075 trace("can't read %d bytes for \"pdbdata\" buffer", nBytes); 1076 free(data); 1077 return TCL_ERROR; 1078 } 1105 proxyPtr->status = TCL_ERROR; 1079 1106 sprintf(fileName, "/tmp/pymol%d.pdb", getpid()); 1080 1107 f = fopen(fileName, "w"); 1081 1108 if (f == NULL) { 1082 trace("can't open `%s': %s", fileName, strerror(errno));1083 perror("pymolproxy");1084 free(data);1085 return TCL_ERROR;1109 Tcl_AppendResult(interp, "can't create temporary file \"", 1110 fileName, "\": ", Tcl_PosixError(interp), 1111 (char *)NULL); 1112 goto error; 1086 1113 } 1087 1114 nWritten = fwrite(data, sizeof(char), nBytes, f); 1088 1115 if (nBytes != nWritten) { 1089 trace("short write %d wanted %d bytes", nWritten, nBytes); 1090 perror("pymolproxy"); 1116 Tcl_AppendResult(interp, "can't write PDB data to \"", 1117 fileName, "\": ", Tcl_PosixError(interp), 1118 (char *)NULL); 1119 fclose(f); 1120 goto error; 1091 1121 } 1092 1122 fclose(f); 1093 free(data);1094 1123 Pymol(proxyPtr, "load %s,%s,%d\n", fileName, name, state); 1124 proxyPtr->status = TCL_OK; 1125 } 1126 error: 1127 if (allocated != NULL) { 1128 free(allocated); 1095 1129 } 1096 1130 return proxyPtr->status;
Note: See TracChangeset
for help on using the changeset viewer.