📄 printutils.c
字号:
} /* Compose the command from the options determined above */ sprintf(command, "%s%s%s%s%s", PrintCommand, copiesArg, queueArg, hostArg, jobArg); /* display it in the command text area */ XmTextSetString(Text4, command); /* Indicate that the command field was synthesized from the other fields, so future dialog invocations can safely re-generate the command without overwriting commands specifically entered by the user */ CmdFieldModified = False;}static void printCmdModified(Widget w, caddr_t client_data, caddr_t call_data){ /* Indicate that the user has specifically modified the print command and that this field should be left as is in subsequent dialogs */ CmdFieldModified = True;}static void printButtonCB(Widget widget, caddr_t client_data, caddr_t call_data){ char *str, command[MAX_CMD_STR];#ifdef VMS int spawn_sts; int spawnFlags=CLI$M_NOCLISYM; struct dsc$descriptor cmdDesc; /* get the print command from the command text area */ str = XmTextGetString(Text4); /* add the file name to the print command */ sprintf(command, "%s %s", str, PrintFileName); XtFree(str); /* append /DELETE to print command if requested */ if (DeleteFile) strcat(command, "/DELETE"); /* spawn the print command */ cmdDesc.dsc$w_length = strlen(command); cmdDesc.dsc$b_dtype = DSC$K_DTYPE_T; cmdDesc.dsc$b_class = DSC$K_CLASS_S; cmdDesc.dsc$a_pointer = command; spawn_sts = lib$spawn(&cmdDesc,0,0,&spawnFlags,0,0,0,0,0,0,0,0); if (spawn_sts != SS$_NORMAL) { DialogF(DF_WARN, widget, 1, "Print Error", "Unable to Print:\n%d - %s\n spawnFlags = %d\n", "Dismiss", spawn_sts, strerror(EVMSERR, spawn_sts), spawnFlags); return; }#else int nRead; FILE *pipe; char errorString[MAX_PRINT_ERROR_LENGTH], discarded[1024]; /* get the print command from the command text area */ str = XmTextGetString(Text4); /* add the file name and output redirection to the print command */ sprintf(command, "cat %s | %s 2>&1", PrintFileName, str); XtFree(str); /* Issue the print command using a popen call and recover error messages from the output stream of the command. */ pipe = popen(command,"r"); if (pipe == NULL) { DialogF(DF_WARN, widget, 1, "Print Error", "Unable to Print:\n%s", "Dismiss", strerror(errno)); return; } errorString[0] = 0; nRead = fread(errorString, sizeof(char), MAX_PRINT_ERROR_LENGTH-1, pipe); /* Make sure that the print command doesn't get stuck when trying to write a lot of output on stderr (pipe may fill up). We discard the additional output, though. */ while (fread(discarded, sizeof(char), 1024, pipe) > 0); if (!ferror(pipe)) { errorString[nRead] = '\0'; } if (pclose(pipe)) { DialogF(DF_WARN, widget, 1, "Print Error", "Unable to Print:\n%s", "Dismiss", errorString); return; }#endif /*(VMS)*/ /* Print command succeeded, so retain the current print parameters */ if (CopiesOption[0] != '\0') { str = XmTextGetString(Text1); strcpy(Copies, str); XtFree(str); } if (QueueOption[0] != '\0') { str = XmTextGetString(Text2); strcpy(Queue, str); XtFree(str); } if (HostOption[0] != '\0') { str = XmTextGetString(Text3); strcpy(Host, str); XtFree(str); } str = XmTextGetString(Text4); strcpy(CmdText, str); XtFree(str); /* Pop down the dialog */ DoneWithDialog = True;}static void cancelButtonCB(Widget widget, caddr_t client_data, caddr_t call_data){ DoneWithDialog = True; CmdFieldModified = False;}#ifndef VMS/*** Is the filename file in the directory dirpath** and does it have at least some of the mode_flags enabled ?*/static int fileInDir(const char *filename, const char *dirpath, unsigned short mode_flags){ DIR *dfile;#ifdef USE_DIRENT struct dirent *DirEntryPtr;#else struct direct *DirEntryPtr;#endif struct stat statbuf; char fullname[MAXPATHLEN]; dfile = opendir(dirpath); if (dfile != NULL) { while ((DirEntryPtr=readdir(dfile)) != NULL) { if (!strcmp(DirEntryPtr->d_name, filename)) { strcpy(fullname,dirpath); strcat(fullname,"/"); strcat(fullname,filename); stat(fullname,&statbuf); closedir(dfile); return statbuf.st_mode & mode_flags; } } closedir(dfile); } return False;}/*** Is the filename file in the environment path directories ** and does it have at least some of the mode_flags enabled ?*/static int fileInPath(const char *filename, unsigned short mode_flags){ char path[MAXPATHLEN]; char *pathstring,*lastchar; /* Get environmental value of PATH */ pathstring = getenv("PATH"); if (pathstring == NULL) return False; /* parse the pathstring and search on each directory found */ do { /* if final path in list is empty, don't search it */ if (!strcmp(pathstring, "")) return False; /* locate address of next : character */ lastchar = strchr(pathstring, SEPARATOR); if (lastchar != NULL) { /* if more directories remain in pathstring, copy up to : */ strncpy(path, pathstring, lastchar-pathstring); path[lastchar-pathstring] = '\0'; } else { /* if it's the last directory, just copy it */ strcpy(path, pathstring); } /* search for the file in this path */ if(fileInDir(filename, path, mode_flags)) return True; /* found it !! */ /* point pathstring to start of new dir string */ pathstring = lastchar + 1; } while( lastchar != NULL ); return False;}/*** Is flpr present in the search path and is it executable ?*/static int flprPresent(void){ /* Is flpr present in the search path and is it executable ? */ return fileInPath("flpr",0111);}static int foundTag(const char *tagfilename, const char *tagname, char *result){ FILE *tfile; char tagformat[512],line[512]; strcpy(tagformat, tagname); strcat(tagformat, " %s"); tfile = fopen(tagfilename,"r"); if (tfile != NULL) { while (!feof(tfile)) { fgets(line,sizeof(line),tfile); if (sscanf(line,tagformat,result) != 0) { fclose(tfile); return True; } } fclose(tfile); } return False;}static int foundEnv(const char *EnvVarName, char *result){ char *dqstr; dqstr = getenv(EnvVarName); if (dqstr != NULL) { strcpy(result,dqstr); return True; } return False;}static void getFlprHostDefault(char *defhost){ if (!foundEnv("FLPHOST",defhost)) if(!foundTag("/usr/local/etc/flp.defaults", "host", defhost)) strcpy(defhost,"");}static void getFlprQueueDefault(char *defqueue){ if (!foundEnv("FLPQUE",defqueue)) if (!foundTag("/usr/local/etc/flp.defaults", "queue", defqueue)) strcpy(defqueue,"");}#ifdef USE_LPR_PRINT_CMDstatic void getLprQueueDefault(char *defqueue){ if (!foundEnv("PRINTER",defqueue)) strcpy(defqueue,"");}#endif#ifndef USE_LPR_PRINT_CMDstatic void getLpQueueDefault(char *defqueue){ if (!foundEnv("LPDEST",defqueue)) defqueue[0] = '\0';}#endif#endif#ifdef VMSstatic void getVmsQueueDefault(char *defqueue){ int translate_sts; short ret_len; char logicl[12], tabl[15]; struct itemList { short bufL; short itemCode; char *queName; short *lngth; int end_entry; } translStruct; struct dsc$descriptor tabName; struct dsc$descriptor logName; sprintf(tabl, "LNM$FILE_DEV"); tabName.dsc$w_length = strlen(tabl); tabName.dsc$b_dtype = DSC$K_DTYPE_T; tabName.dsc$b_class = DSC$K_CLASS_S; tabName.dsc$a_pointer = tabl; sprintf(logicl, "SYS$PRINT"); logName.dsc$w_length = strlen(logicl); logName.dsc$b_dtype = DSC$K_DTYPE_T; logName.dsc$b_class = DSC$K_CLASS_S; logName.dsc$a_pointer = logicl; translStruct.itemCode = LNM$_STRING; translStruct.lngth = &ret_len; translStruct.bufL = 99; translStruct.end_entry = 0; translStruct.queName = defqueue; translate_sts = sys$trnlnm(0,&tabName,&logName,0,&translStruct); if (translate_sts != SS$_NORMAL && translate_sts != SS$_NOLOGNAM){ fprintf(stderr, "Error return from sys$trnlnm: %d\n", translate_sts); DialogF(DF_WARN, Label2, 1, "Error", "Error translating SYS$PRINT", "Dismiss"); defqueue[0] = '\0'; } else {/* printf("return status from sys$trnlnm = %d\n", translate_sts); */ if (translate_sts == SS$_NOLOGNAM) { defqueue[0] = '\0'; } else { strncpy(defqueue, translStruct.queName, ret_len); defqueue[ret_len] = '\0';/* printf("defqueue = %s, length = %d\n", defqueue, ret_len); */ } } }#endif /*(VMS)*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -