Exemplo n.º 1
0
void option_list_add( OptionList** ppOptList,
					  const char* key, const char* value, short flg )
{

	if( option_list_get_value(*ppOptList,key, NULL) == NULL ){
		OptionList *plist = (OptionList*)malloc(sizeof(OptionList));

		plist->key = strdup(key);
		plist->value = strdup(value);
		plist->change_flg = 0;
		plist->updf_flg = flg;

		plist->next = *ppOptList;
		*ppOptList = plist;
	}
	else{
		option_list_change_value(*ppOptList, key, value, flg);
	}


}
Exemplo n.º 2
0
int cnpkGetPageInfo( CnpkCtx* pCnpk, CnpkPageInfo* pPageInfo )
{
	int result = 0;
	int data_size = 0;
	char *pData;

#ifdef DEBUG_MESSAGE
	fputs("DEBUG: cnpkGetPageInfo\n", stderr);
#endif

	if( pCnpk->flgProc ){
		if( cnprocWriteCommand(pCnpk->pipe_fds, CNPK_ID_GET_PAGEINFO, NULL,
							   0) < 0 )
			return CNPK_ERROR;
		result = cnprocCheckResponse(pCnpk->pipe_fds, CNPK_ID_GET_PAGEINFO,
									 &data_size, &pData );

		if( result == 0 && pData != NULL ){
			char *pName;
			char *pValue;
			char *ptr = NULL;

			ptr = pData;

			while( *ptr != '\0'){

				while( isspace(*ptr) )
					ptr++;
				pName = ptr;

				while( *ptr != '='  && *ptr != '\0' )
					ptr++;
				*ptr = '\0'; ptr++;

				while( isspace(*ptr) )
					ptr++;

				pValue = ptr;
				while( *ptr != ';' && *ptr !='\0')
					ptr++;
				if( *ptr != '\0' ){
					*ptr = '\0';
					ptr++;
				}
				if( !strcmp(pName, "page_name") ){
					strncpy(pPageInfo->page_name, pValue, MAX_PAGE_INFO-1);
					pPageInfo->page_name[MAX_PAGE_INFO-1] = '\0';
				}else if( !strcmp(pName, "page_orient") ){
					strncpy(pPageInfo->page_orient, pValue, MAX_PAGE_INFO-1);
					pPageInfo->page_orient[MAX_PAGE_INFO-1] = '\0';
				}else if( !strcmp(pName, "resolution") ){
					strncpy(pPageInfo->resolution, pValue, MAX_PAGE_INFO-1);
					pPageInfo->resolution[MAX_PAGE_INFO-1] = '\0';
				}else if( !strcmp(pName, "color_mode") ){
					strncpy(pPageInfo->color_mode, pValue, MAX_PAGE_INFO-1);
					pPageInfo->color_mode[MAX_PAGE_INFO-1] = '\0';
				}else if( !strcmp(pName, "media_type") ){
					strncpy(pPageInfo->media_type, pValue, MAX_PAGE_INFO-1);
					pPageInfo->media_type[MAX_PAGE_INFO-1] = '\0';
				}else if( !strcmp(pName, "toner_save") ){
					strncpy(pPageInfo->toner_save, pValue, MAX_PAGE_INFO-1);
					pPageInfo->toner_save[MAX_PAGE_INFO-1] = '\0';
				}else if( !strcmp(pName, "bind_edge") ){
					strncpy(pPageInfo->bind_edge, pValue, MAX_PAGE_INFO-1);
					pPageInfo->bind_edge[MAX_PAGE_INFO-1] = '\0';
				}else if( !strcmp(pName, "bind_edge_shift") ){
					strncpy(pPageInfo->bind_edge_shift,
						   pValue, MAX_PAGE_INFO-1);
					pPageInfo->bind_edge_shift[MAX_PAGE_INFO-1] = '0';
				}else if( !strcmp(pName, "duplex") ){
					strncpy(pPageInfo->duplex, pValue, MAX_PAGE_INFO-1);
					pPageInfo->bind_edge_shift[MAX_PAGE_INFO-1] = '\0';
				}
			}
			free(pData);
		}
	}else{
		int model_method = 0;

		if( pPageInfo == NULL )
			return -1;

		memset(pPageInfo, 0, sizeof(CnpkPageInfo));

		{
			char *pValue = NULL;
			if( (pValue = option_list_get_value(pCnpk->pOptList,
											"CNModelMethod", NULL)) != NULL){
				model_method = atoi(pValue);
				free(pValue);
			}
		}

		{
			char *pValue = NULL;
			if( (pValue = option_list_get_value(pCnpk->pOptList,
											"PageSize", NULL)) != NULL){
				strncpy(pPageInfo->page_name, pValue, MAX_PAGE_INFO-1);
				pPageInfo->page_name[MAX_PAGE_INFO-1] = '\0';
				free(pValue);
			}else{
				strcpy(pPageInfo->page_name, "A4");
			}
		}

		{
			char *pValue = NULL;
			if( (pValue = option_list_get_value(pCnpk->pOptList,
											"Resolution", NULL)) != NULL){
				strncpy(pPageInfo->resolution, pValue, MAX_PAGE_INFO-1);
				pPageInfo->resolution[MAX_PAGE_INFO-1] = '\0';
				free(pValue);
			}else{
				strcpy(pPageInfo->resolution, "600");
			}
		}

		{
			char *pValue = NULL;
			if( (pValue = option_list_get_value(pCnpk->pOptList,
											"Orientation", NULL)) != NULL){
				strncpy(pPageInfo->page_orient, pValue, MAX_PAGE_INFO-1);
				pPageInfo->page_orient[MAX_PAGE_INFO-1] = '\0';
				free(pValue);
			}else{
				strcpy(pPageInfo->page_orient, "portrait");
			}
		}

		{
			char *pValue = NULL;
			if( (pValue = option_list_get_value(pCnpk->pOptList,
											"CNColorMode", NULL)) != NULL){
				if( !strcmp(pValue, "mono") ){
					strcpy(pPageInfo->color_mode, "gray");
				}
				else
					strcpy(pPageInfo->color_mode, "color");
				free(pValue);
			}else{
				strcpy(pPageInfo->color_mode, "gray");
			}
		}

		{
			char *pValue = NULL;
			pPageInfo->media_type[0] = '\0';
			if( model_method & METHOD_MEDIA_TYPE ){
				if( (pValue = option_list_get_value(pCnpk->pOptList,
												"MediaType", NULL)) != NULL){
					char *slot = NULL;
					if( (slot = option_list_get_value(pCnpk->pOptList,
											  "InputSlot", NULL)) != NULL){
						if( !strcasecmp(slot, "Auto") ||
							!strcasecmp(slot, "Manual") ){
							strncpy(pPageInfo->media_type,
									pValue, MAX_PAGE_INFO-1);
							pPageInfo->media_type[MAX_PAGE_INFO-1] = '\0';
						}
						free(slot);
					}
					free(pValue);
				}
			}else{
				pPageInfo->media_type[0] = '\0';
			}
		}

		{
			if( model_method & METHOD_TONER_SAVE ){
				char *pValue = NULL;
				if( (pValue = option_list_get_value(pCnpk->pOptList,
											"CNTonerSaving", NULL)) != NULL){
					strncpy(pPageInfo->toner_save, pValue, MAX_PAGE_INFO-1);
					pPageInfo->toner_save[MAX_PAGE_INFO-1] = '\0';
					free(pValue);
				}else{
					pPageInfo->media_type[0] = '\0';
				}
			}else{
				pPageInfo->media_type[0] = '\0';
			}
		}

		{

			char *pValue = NULL;
			if( (pValue = option_list_get_value(pCnpk->pOptList,
											"BindEdge", NULL)) != NULL){
				strncpy(pPageInfo->bind_edge, pValue, MAX_PAGE_INFO-1);
				pPageInfo->bind_edge[MAX_PAGE_INFO-1] = '\0';
				free(pValue);
			}else{
				strcpy(pPageInfo->bind_edge, "Left");
			}
		}



		{
			char *pMaxGutt = NULL;
			char *pValue = NULL;
			int shift = 0;
			int nMaxGutt = 30;

			if( (pMaxGutt = option_list_get_value(pCnpk->pOptList,
											  "CNMaxGutter", NULL)) != NULL){
				nMaxGutt =atoi(pMaxGutt);
				free(pMaxGutt);
			}

			if( (pValue = option_list_get_value(pCnpk->pOptList,
										"CNBindEdgeShift", NULL)) != NULL){
				shift =atoi(pValue);
				if( shift < 0 ){
					strcpy(pPageInfo->bind_edge_shift, "0");
				}
				else if( shift > nMaxGutt ){
					char bufTmp[64];
					snprintf(bufTmp, 63, "%d", nMaxGutt);
					strncpy(pPageInfo->bind_edge_shift,
							bufTmp, MAX_PAGE_INFO-1);
					pPageInfo->bind_edge[MAX_PAGE_INFO-1] = '\0';
				}
				else{
					strncpy(pPageInfo->bind_edge_shift,
							pValue, MAX_PAGE_INFO-1);
					pPageInfo->bind_edge_shift[MAX_PAGE_INFO-1] = '0';
				}
				free(pValue);
			}else{
				strcpy(pPageInfo->bind_edge_shift, "0");
			}
		}

		{

			char *pValue = NULL;
			if( (pValue = option_list_get_value(pCnpk->pOptList,
											"Duplex", NULL)) != NULL){
				if( (strcmp(pValue, "False") == 0 ) ||
					(strcmp(pValue, "None") == 0 ) ){
					strncpy(pPageInfo->duplex, "False", MAX_PAGE_INFO-1);
					pPageInfo->duplex[MAX_PAGE_INFO-1] = '\0';
				}else{
					strncpy(pPageInfo->duplex, "True", MAX_PAGE_INFO-1);
					pPageInfo->duplex[MAX_PAGE_INFO-1] = '\0';
				}
				free(pValue);
			}else{
				strcpy(pPageInfo->duplex, "False");
			}
		}



	}

		return result;
}