static string kpse_expand_kpse_dot P1C(string, path) { string ret, elt; string kpse_dot = getenv("KPSE_DOT"); #ifdef MSDOS boolean malloced_kpse_dot = false; #endif if (kpse_dot == NULL) return path; ret = (string)xmalloc(1); *ret = 0; #ifdef MSDOS /* Some setups of ported Bash force $KPSE_DOT to have the //d/foo/bar form (when `pwd' is used), which is not understood by libc and the OS. Convert them back to the usual d:/foo/bar form. */ if (kpse_dot[0] == '/' && kpse_dot[1] == '/' && kpse_dot[2] >= 'A' && kpse_dot[2] <= 'z' && kpse_dot[3] == '/') { kpse_dot++; kpse_dot = xstrdup (kpse_dot); kpse_dot[0] = kpse_dot[1]; /* drive letter */ kpse_dot[1] = ':'; malloced_kpse_dot = true; } #endif for (elt = kpse_path_element (path); elt; elt = kpse_path_element (NULL)) { string save_ret = ret; boolean ret_copied = true; /* We assume that the !! magic is only used on absolute components. Single "." gets special treatment, as does "./" or its equivalent. */ if (kpse_absolute_p (elt, false) || (elt[0] == '!' && elt[1] == '!')) { ret = concat3(ret, elt, ENV_SEP_STRING); } else if (elt[0] == '.' && elt[1] == 0) { ret = concat3 (ret, kpse_dot, ENV_SEP_STRING); #ifndef VMS } else if (elt[0] == '.' && IS_DIR_SEP(elt[1])) { ret = concatn (ret, kpse_dot, elt + 1, ENV_SEP_STRING, NULL); } else if (*elt) { ret = concatn (ret, kpse_dot, DIR_SEP_STRING, elt, ENV_SEP_STRING, NULL); #endif } else { /* omit empty path elements from TEXMFCNF. See http://bugs.debian.org/358330. */ ret_copied = false; } if (ret_copied) free (save_ret); } #ifdef MSDOS if (malloced_kpse_dot) free (kpse_dot); #endif ret[strlen (ret) - 1] = 0; return ret; }
int main() { char str1[1000],str2[1000]; while(scanf("%s%s",str1,str2)!=EOF) { concatn(str1,str2); printf("%s\n",str1); } return 0; }
int main () { printf ("null = \"%s\"\n", concatn (NULL)); printf ("\"a\" = \"%s\"\n", concatn ("a", NULL)); printf ("\"ab\" = \"%s\"\n", concatn ("a", "b", NULL)); printf ("\"abc\" = \"%s\"\n", concatn ("a", "b", "c", NULL)); printf ("\"abcd\" = \"%s\"\n", concatn ("ab", "cd", NULL)); printf ("\"abcde\" = \"%s\"\n", concatn ("ab", "c", "de", NULL)); printf ("\"abcdef\" = \"%s\"\n", concatn ("", "a", "", "bcd", "ef", NULL)); return 0; }
CFileSize seek_beginning_of_archive(CFileInStream *archive_stream) { UInt32 i; int is_found; char* pylauncher = "@@@pylauncher@@@"; char* signature = concatn(pylauncher, (char*)k7zSignature, k7zSignatureSize, false); if(!signature) return 1; int signature_size = strlen(signature); int result; size_t archive_size = 0; #ifdef DEBUG printf("signature: '%s'\n", signature); #endif #ifdef USE_WINDOWS_FUNCTIONS archive_size = 1000000 //TBD #else struct stat filestat; fstat(fileno(archive_stream->File), &filestat); archive_size = filestat.st_size; #endif is_found = false; Byte b[signature_size]; #ifdef DEBUG printf("archive_size=%d", archive_size); #endif for (i=0; i < archive_size; i++){ result = seek_file_imp(archive_stream, i); result = read_file(archive_stream->File, &b, signature_size); if (result == 0){ break; } if(memcmp(signature, b, signature_size) == 0) { is_found = true; break; } } #ifdef DEBUG printf("signature=%s, offset=%d, found=%i\n", b, i, is_found); #endif if (! is_found){ print_error("Could not find the beginning of the archive"); } free(signature); return (CFileSize)(i + strlen(pylauncher)); }
int shell_cmd_is_allowed(const char *cmd, char **safecmd, char **cmdname) { char **p; char *buf; char *c, *d; const char *s; int pre; unsigned spaces; int allow = 0; /* pre == 1 means that the previous character is a white space pre == 0 means that the previous character is not a white space */ buf = xmalloc(strlen(cmd) + 1); strcpy(buf, cmd); c = buf; while (Isspace(*c)) c++; d = c; while (!Isspace(*d) && *d) d++; *d = '\0'; /* *cmdname is the first word of the command line. For example, *cmdname == "kpsewhich" for: \write18{kpsewhich --progname=dvipdfm --format="other text files" config} */ *cmdname = xstrdup(c); free(buf); /* Is *cmdname listed in a texmf.cnf vriable as shell_escape_commands = foo,bar,... ? */ p = cmdlist; if (p) { while (*p) { if (strcmp(*p, *cmdname) == 0) { /* *cmdname is found in the list, so restricted shell escape is allowed */ allow = 2; break; } p++; } } if (allow == 2) { spaces = 0; for (s = cmd; *s; s++) { if (Isspace(*s)) spaces++; } /* allocate enough memory (too much?) */ # ifdef WIN32 *safecmd = xmalloc(2 * strlen(cmd) + 3 + 2 * spaces); # else *safecmd = xmalloc(strlen(cmd) + 3 + 2 * spaces); # endif /* make a safe command line *safecmd */ s = cmd; while (Isspace(*s)) s++; d = *safecmd; while (!Isspace(*s) && *s) *d++ = *s++; pre = 1; while (*s) { /* Quotation given by a user. " should always be used; we transform it below. On Unix, if ' is used, simply immediately return a quotation error. */ if (*s == '\'') { return -1; } if (*s == '"') { /* All arguments are quoted as 'foo' (Unix) or "foo" (Windows) before calling system(). Therefore closing QUOTE is necessary if the previous character is not a white space. For example: --format="other text files" becomes '--format=''other text files' (Unix) "--format"="other text files" (Windows) */ if (pre == 0) { # ifdef WIN32 if (*(s-1) == '=') { *(d-1) = QUOTE; *d++ = '='; } else { *d++ = QUOTE; } # else *d++ = QUOTE; # endif } pre = 0; /* Output the quotation mark for the quoted argument. */ *d++ = QUOTE; s++; while (*s != '"') { /* Illegal use of ', or closing quotation mark is missing */ if (*s == '\'' || *s == '\0') return -1; # if 0 # ifdef WIN32 if (char_needs_quote(*s)) *d++ = '^'; # endif # endif *d++ = *s++; } /* Closing quotation mark will be output afterwards, so we do nothing here. */ s++; /* The character after the closing quotation mark should be a white space or NULL. */ if (!Isspace(*s) && *s) return -1; /* Beginning of a usual argument. */ } else if (pre == 1 && !Isspace(*s)) { pre = 0; *d++ = QUOTE; # if 0 # ifdef WIN32 if (char_needs_quote(*s)) *d++ = '^'; # endif # endif *d++ = *s++; /* Ending of a usual argument. */ } else if (pre == 0 && Isspace(*s)) { pre = 1; /* Closing quotation mark */ *d++ = QUOTE; *d++ = *s++; } else { /* Copy a character from cmd to *safecmd. */ # if 0 # ifdef WIN32 if (char_needs_quote(*s)) *d++ = '^'; # endif # endif *d++ = *s++; } } /* End of the command line. */ if (pre == 0) { *d++ = QUOTE; } *d = '\0'; #ifdef WIN32 { char *p, *q, *r; p = *safecmd; if (strlen (p) > 2 && p[1] == ':' && !IS_DIR_SEP (p[2])) { q = xmalloc (strlen (p) + 2); q[0] = p[0]; q[1] = p[1]; q[2] = '/'; q[3] = '\0'; strcat (q, (p + 2)); free (*safecmd); *safecmd = q; } else if (!IS_DIR_SEP (p[0]) && !(p[1] == ':' && IS_DIR_SEP (p[2]))) { p = kpse_var_value ("SELFAUTOLOC"); if (p) { r = *safecmd; while (*r && !Isspace(*r)) r++; if (*r == '\0') q = concatn ("\"", p, "/", *safecmd, "\"", NULL); else { *r = '\0'; r++; while (*r && Isspace(*r)) r++; if (*r) q = concatn ("\"", p, "/", *safecmd, "\" ", r, NULL); else q = concatn ("\"", p, "/", *safecmd, "\"", NULL); } free (p); free (*safecmd); *safecmd = q; } } } #endif } return allow; }
FILE * __cdecl kpathsea_win32_popen (kpathsea kpse, const char *cmd, const char *fmode) { char mode[3]; STARTUPINFO si; PROCESS_INFORMATION pi; SECURITY_ATTRIBUTES sa = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE }; FILE *f = NULL; int fno, i; HANDLE child_in, child_out; HANDLE father_in, father_out; HANDLE father_in_dup, father_out_dup; HANDLE current_in, current_out; HANDLE current_pid; char *env_path; int binary_mode; char *new_cmd, *app_name = NULL; char *p, *q; struct _popen_elt *new_process; char pname[MAXPATHLEN], *fp; char *suffixes[] = { ".bat", ".cmd", ".com", ".exe", NULL }; char **s; BOOL go_on; /* We always use binary mode */ mode[0] = fmode[0]; mode[1] = 'b'; mode[2] = '\0'; /* We should look for the application name along the PATH, and decide to prepend "%COMSPEC% /c " or not to the command line. Do nothing for the moment. */ /* Another way to do that would be to try CreateProcess first without invoking cmd, and look at the error code. If it fails because of command not found, try to prepend "cmd /c" to the cmd line. */ /* Look for the application name */ for (p = (char *)cmd; *p && isspace(*p); p++); if (*p == '"') { q = ++p; while(*p && *p != '"') p++; if (*p == '\0') { fprintf(stderr, "popen: malformed command (\" not terminated)\n"); return NULL; } } else for (q = p; *p && !isspace(*p); p++); /* q points to the beginning of appname, p to the last + 1 char */ if ((app_name = malloc(p - q + 1)) == NULL) { fprintf(stderr, "xpopen: malloc(app_name) failed.\n"); return NULL; } strncpy(app_name, q, p - q ); app_name[p - q] = '\0'; pname[0] = '\0'; #ifdef TRACE fprintf(stderr, "popen: app_name = %s\n", app_name); #endif { char *tmp = getenv("PATH"); env_path = xmalloc(strlen(tmp) + 3); strcpy(env_path, tmp); strcat(env_path, ";."); } /* Looking for appname on the path */ for (s = suffixes, go_on = TRUE; go_on; *s++) { if (SearchPath(env_path, /* Address of search path */ app_name, /* Address of filename */ *s, /* Address of extension */ MAXPATHLEN, /* Size of destination buffer */ pname, /* Address of destination buffer */ &fp) /* File part of app_name */ != 0 && *s) { /* added *s in order not to allow no suffix. --ak 2009/10/24 */ #ifdef TRACE fprintf(stderr, "%s found with suffix %s\nin %s\n", app_name, *s, pname); #endif new_cmd = xstrdup(cmd); free(app_name); app_name = xstrdup(pname); break; } go_on = (*s != NULL); } if (go_on == FALSE) { /* the app_name was not found */ #ifdef TRACE fprintf(stderr, "%s not found, concatenating comspec\n", app_name); #endif new_cmd = concatn("cmd.exe", " /c ", cmd, NULL); free(app_name); app_name = NULL; } if (env_path) free(env_path); #ifdef TRACE fprintf(stderr, "popen: app_name = %s\n", app_name); fprintf(stderr, "popen: cmd_line = %s\n", new_cmd); #endif current_in = GetStdHandle(STD_INPUT_HANDLE); current_out = GetStdHandle(STD_OUTPUT_HANDLE); current_pid = GetCurrentProcess(); ZeroMemory( &si, sizeof(STARTUPINFO) ); si.cb = sizeof(STARTUPINFO); si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; si.wShowWindow = SW_HIDE; if (strchr(mode, 'b')) binary_mode = _O_BINARY; else binary_mode = _O_TEXT; /* Opening the pipe for writing */ if (strchr(mode, 'w')) { binary_mode |= _O_WRONLY; if (CreatePipe(&child_in, &father_out, &sa, 0) == FALSE) { fprintf(stderr, "popen: error CreatePipe\n"); return NULL; } si.hStdInput = child_in; si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); si.hStdError = GetStdHandle(STD_ERROR_HANDLE); if (DuplicateHandle(current_pid, father_out, current_pid, &father_out_dup, 0, FALSE, DUPLICATE_SAME_ACCESS) == FALSE) { fprintf(stderr, "popen: error DuplicateHandle father_out\n"); return NULL; } CloseHandle(father_out); fno = _open_osfhandle((long)father_out_dup, binary_mode); f = _fdopen(fno, mode); i = setvbuf( f, NULL, _IONBF, 0 ); } /* Opening the pipe for reading */ else if (strchr(mode, 'r')) { binary_mode |= _O_RDONLY; if (CreatePipe(&father_in, &child_out, &sa, 0) == FALSE) { fprintf(stderr, "popen: error CreatePipe\n"); return NULL; } si.hStdInput = GetStdHandle(STD_INPUT_HANDLE); si.hStdOutput = child_out; si.hStdError = GetStdHandle(STD_ERROR_HANDLE); if (DuplicateHandle(current_pid, father_in, current_pid, &father_in_dup, 0, FALSE, DUPLICATE_SAME_ACCESS) == FALSE) { fprintf(stderr, "popen: error DuplicateHandle father_in\n"); return NULL; } CloseHandle(father_in); fno = _open_osfhandle((long)father_in_dup, binary_mode); f = _fdopen(fno, mode); i = setvbuf( f, NULL, _IONBF, 0 ); } else { fprintf(stderr, "popen: invalid mode %s\n", mode); return NULL; } /* creating child process */ if (CreateProcess(app_name, /* pointer to name of executable module */ new_cmd, /* pointer to command line string */ NULL, /* pointer to process security attributes */ NULL, /* pointer to thread security attributes */ TRUE, /* handle inheritance flag */ 0, /* creation flags, do not touch this again ! (16/06/98) */ NULL, /* pointer to environment */ NULL, /* pointer to current directory */ &si, /* pointer to STARTUPINFO */ &pi /* pointer to PROCESS_INFORMATION */ ) == FALSE) { fprintf(stderr, "popen: CreateProcess %x\n", GetLastError()); return NULL; } /* Only the process handle is needed */ if (CloseHandle(pi.hThread) == FALSE) { fprintf(stderr, "popen: error closing thread handle\n"); return NULL; } if (new_cmd) free(new_cmd); if (app_name) free(app_name); /* Add the pair (f, pi.hProcess) to the list */ if ((new_process = malloc(sizeof(struct _popen_elt))) == NULL) { fprintf (stderr, "popen: malloc(new_process) error\n"); return NULL; } /* Saving the FILE * pointer, access key for retrieving the process handle later on */ new_process->f = f; /* Closing the unnecessary part of the pipe */ if (strchr(mode, 'r')) { CloseHandle(child_out); } else if (strchr(mode, 'w')) { CloseHandle(child_in); } /* Saving the process handle */ new_process->hp = pi.hProcess; /* Linking it to the list of popen() processes */ new_process->next = kpse->_popen_list; kpse->_popen_list = new_process; return f; }
int main(int argc, char *argv[]) { int i; int retval = 0; kpse_set_progname(argv[0]); progname = xstrdup(program_invocation_short_name); #ifdef _WIN32 SetConsoleCtrlHandler((PHANDLER_ROUTINE)sigint_handler, TRUE); #else # ifdef SIGHUP signal (SIGHUP, sigint_handler); # endif # ifdef SIGINT signal (SIGINT, sigint_handler); # endif # ifdef SIGQUIT signal (SIGQUIT, sigint_handler); # endif # ifdef SIGEMT signal (SIGEMT, sigint_handler); # endif # ifdef SIGPIPE signal (SIGPIPE, sigint_handler); # endif # ifdef SIGTERM signal (SIGTERM, sigint_handler); # endif #endif if (strlen(progname) > 4 && FILESTRNCASEEQ(progname + strlen(progname) - 4, ".exe", 4)) { *(progname + strlen(progname) - 4) = '\0'; } is_ht = FILESTRCASEEQ(progname, "ht"); argv = parse_arguments(&argc, argv); #if 0 fprintf(stderr, "%s:\n", progname); for (i = 1; i < argc; i++) fprintf(stderr, "\t argv[%d] = %s\n", i, argv[i]); fprintf(stderr, "\nconfig(%d,%d) = ", math, dtd); for (i = 0; i < 3; i++) fprintf(stderr, "%s ", stdcfg[math][dtd][i]); fprintf(stderr, "\n"); #endif texargs = (force ? "--interaction=nonstopmode" : ""); if (TESTZ(argv[1])) { fprintf(stderr, "%s: error, no file specified.\n", progname); exit(1); } texsrc = xstrdup(argv[1]); #if 0 /* Rely on latex / kpathsea to find the right source file. */ if ((strlen(texsrc) < 4) || _strnicmp(texsrc + strlen(texsrc) - 4, ".tex", 4) != 0) { texsrc = concat(texsrc, ".tex"); } #endif texfile = xstrdup(texsrc); if ((strlen(texfile) >= 4) && _strnicmp(texfile + strlen(texfile) - 4, ".tex", 4) == 0) { *(texfile + strlen(texfile) - 4) = '\0'; } if (TESTZ(output_name)) { output_name = xstrdup(texfile); } else { if ((strlen(output_name) >= 4) && _strnicmp(output_name + strlen(output_name) - 4, ".tex", 4) == 0) { *(output_name + strlen(output_name) - 4) = '\0'; } texargs = concat3(texargs, " --jobname=", output_name); } #if 0 // copy the original name to output name if needed if (TESTNZ(output_dir)) { texfile = concat3(output_dir, "\\", output_name); } else if (TESTNZ(output_name)) { texfile = xstrdup(output_name); } else texfile = NULL; if (texfile) { unixtodos_filename(texfile); if (dry_run) { fprintf(stderr, "%s: copying %s to %s\n", progname, texsrc, texfile); } else { if (CopyFile(texsrc, texfile, false) == 0) { fprintf(stderr, "%s: failed to copy %s to %s (Error %d)\n", progname, texsrc, texfile, GetLastError()); } } free(texfile); } texfile = xstrdup(output_name); if (TESTNZ(output_dir)) { pushd(output_dir); xputenv("KPSE_DOT", cwd); xputenv("TEXINPUTS", concatn(cwd, "/", output_dir, ";", NULL)); if (dry_run) { fprintf(stderr, "%s: changing directory to %s\n", progname, output_dir); fprintf(stderr, "%s: setting KPSE_DOT to %s\n", progname, cwd); } } #endif if (is_ht) { retval = ht(argc, argv); } else if (FILESTRCASEEQ(progname, "httex")) { retval = ht_engine(runstr_tex, argc, argv); } else if (FILESTRCASEEQ(progname, "htlatex")) { retval = ht_engine(runstr_latex, argc, argv); } else if (FILESTRCASEEQ(progname, "httexi")) { retval = ht_engine(runstr_texi, argc, argv); } else { fprintf(stderr, "%s: %s is unknown, aborting.\n", argv[0], progname); retval = 1; } if (opt_index) { /* copy dest_dir/output_name.html to dest_dir/index.html */ char *destfile = output_name; char *indexfile = "index.html"; if (TESTNZ(output_dir)) { destfile = concat3(output_dir, "\\", output_name); indexfile = concat(output_dir, "\\index.html"); } if ((strlen(destfile) < 5) || _strnicmp(destfile + strlen(destfile) - 5, ".html", 5) != 0) { destfile = concat(destfile, ".html"); } if (CopyFile(destfile, indexfile, false) == 0) { fprintf(stderr, "%s: failed to copy %s to %s (Error %d)\n", progname, destfile, indexfile, GetLastError()); } } mt_exit(retval); /* Not Reached */ return retval; }
void badpk(const char *s) { char *msg = concatn ("! Bad PK file ", name, ": ", s, NULL); error(msg); }
static Boolean pkopen(register fontdesctype *fd) { register char *d, *n; const char *name_ret; #ifdef KPATHSEA int dpi_ret; #else int vdpi; #endif d = fd->area; n = fd->name; #ifndef KPATHSEA if (*d==0) d = pkpath; #endif #ifdef FONTLIB if (*(fd->area) == 0) { int del; for (del=0; del<=RES_TOLERANCE(fd->dpi); del=del>0?-del:-del+1) { if ((pkfile=flisearch(n, fd->dpi + del)) != (FILE *)NULL ) return(1); } } #endif { #ifdef KPATHSEA char *this_name = concat (d, n); pkfile = pksearch(this_name, READBIN, fd->dpi, &name_ret, &dpi_ret); if (!pkfile || !FILESTRCASEEQ (this_name, name_ret)) { char *msg = concatn ("Font ", fd->area, n, " not found; ", NULL); /* wasting some memory */ if (!pkfile) msg = concat (msg, "characters will be left blank."); else msg = concat3 (msg, "using ", name_ret); dontmakefont = 1; error (msg); } else if (!kpse_bitmap_tolerance ((double) dpi_ret, (double) fd->dpi)) { fd->loadeddpi = dpi_ret; fd->alreadyscaled = 0; sprintf(errbuf, "Font %s at %d not found; scaling %d instead.", n, fd->dpi, dpi_ret); error(errbuf); lectureuser(); } if (this_name != name_ret) free (this_name); return pkfile != NULL; } #else int del; for (del=0; del<=RES_TOLERANCE(fd->dpi); del=del>0?-del:-del+1) { if (actualdpi == vactualdpi) { vdpi = 0; } else { vdpi = (2 * ((long)vactualdpi) * (fd->dpi + del) + actualdpi) / (2 * actualdpi); } #ifdef MVSXA sprintf(name, "pk%d(%s)", fd->dpi + del, n); #else sprintf(name, "%s.%dpk", n, fd->dpi + del); #endif if (0 != (pkfile=pksearch(d, name, READBIN, n, fd->dpi + del, vdpi))) return(1); } }