int synctex_test_file (int argc, char *argv[]) { int arg_index = 0; char * output = NULL; char * directory = NULL; char * synctex_name = NULL; synctex_compress_mode_t mode = synctex_compress_mode_none; if(arg_index>=argc) { _synctex_error("! usage: synctex test file -o output [-d directory]\n"); return -1; } /* required */ if((arg_index>=argc) || strcmp("-o",argv[arg_index]) || (++arg_index>=argc)) { _synctex_error("! usage: synctex test file -o output [-d directory]\n"); return -1; } output = argv[arg_index]; /* optional */ if(++arg_index<argc) { if(0 == strcmp("-d",argv[arg_index])) { if(++arg_index<argc) { directory = argv[arg_index]; } else { directory = getenv("SYNCTEX_BUILD_DIRECTORY"); } } } /* Arguments parsed */ if(_synctex_get_name(output, directory, &synctex_name, &mode)) { _synctex_error("! TEST FAILED\n"); } else { printf("output:%s\n" "directory:%s\n" "file name:%s\n" "compression mode:%s\n", output, directory, synctex_name, (mode?"gz":"none")); } return 0; }
char * _synctex_merge_strings(const char * first,...) { va_list arg; size_t size = 0; const char * temp; /* First retrieve the size necessary to store the merged string */ va_start (arg, first); temp = first; do { size_t len = strlen(temp); if(UINT_MAX-len<size) { _synctex_error("! _synctex_merge_strings: Capacity exceeded."); va_end(arg); return NULL; } size+=len; } while( (temp = va_arg(arg, const char *)) != NULL); va_end(arg); if(size>0) { char * result = NULL; ++size; /* Create the memory storage */ if(NULL!=(result = (char *)malloc(size))) { char * dest = result; va_start (arg, first); temp = first; do { if((size = strlen(temp))>0) { /* There is something to merge */ if(dest != strncpy(dest,temp,size)) { _synctex_error("! _synctex_merge_strings: Copy problem"); free(result); result = NULL; va_end(arg); return NULL; } dest += size; } } while( (temp = va_arg(arg, const char *)) != NULL); va_end(arg); dest[0]='\0';/* Terminate the merged string */ return result; }
int _synctex_copy_with_quoting_last_path_component(const char * src, char ** dest_ref, size_t size) { const char * lpc; if(src && dest_ref) { # define dest (*dest_ref) dest = NULL; /* Default behavior: no change and sucess. */ lpc = _synctex_last_path_component(src); if(strlen(lpc)) { if(strchr(lpc,' ') && lpc[0]!='"' && lpc[strlen(lpc)-1]!='"') { /* We are in the situation where adding the quotes is allowed. */ /* Time to add the quotes. */ /* Consistency test: we must have dest+size>dest+strlen(dest)+2 * or equivalently: strlen(dest)+2<size (see below) */ if(strlen(src)<size) { if((dest = (char *)malloc(size+2))) { char * dpc = dest + (lpc-src); /* dpc is the last path component of dest. */ if(dest != strncpy(dest,src,size)) { _synctex_error("! _synctex_copy_with_quoting_last_path_component: Copy problem"); free(dest); dest = NULL;/* Don't forget to reinitialize. */ return -2; } memmove(dpc+1,dpc,strlen(dpc)+1); /* Also move the null terminating character. */ dpc[0]='"'; dpc[strlen(dpc)+1]='\0';/* Consistency test */ dpc[strlen(dpc)]='"'; return 0; /* Success. */ } return -1; /* Memory allocation error. */ } _synctex_error("! _synctex_copy_with_quoting_last_path_component: Internal inconsistency"); return -3; } return 0; /* Success. */ } return 0; /* No last path component. */ # undef dest } return 1; /* Bad parameter, this value is subject to changes. */ }